@react-native-ohos/react-native-blurhash 2.0.4-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.OpenSource +11 -0
- package/README.md +13 -0
- package/harmony/blurhash/BuildProfile.ets +17 -0
- package/harmony/blurhash/build-profile.json5 +9 -0
- package/harmony/blurhash/hvigorfile.ts +2 -0
- package/harmony/blurhash/index.ets +2 -0
- package/harmony/blurhash/oh-package.json5 +13 -0
- package/harmony/blurhash/src/main/cpp/Blurhash.cpp +314 -0
- package/harmony/blurhash/src/main/cpp/Blurhash.hpp +27 -0
- package/harmony/blurhash/src/main/cpp/BlurhashNode.cpp +87 -0
- package/harmony/blurhash/src/main/cpp/BlurhashNode.h +35 -0
- package/harmony/blurhash/src/main/cpp/BlurhashPackage.h +53 -0
- package/harmony/blurhash/src/main/cpp/BlurhashViewComponentInstance.cpp +137 -0
- package/harmony/blurhash/src/main/cpp/BlurhashViewComponentInstance.h +34 -0
- package/harmony/blurhash/src/main/cpp/BlurhashViewJSIBinder.h +34 -0
- package/harmony/blurhash/src/main/cpp/CMakeLists.txt +13 -0
- package/harmony/blurhash/src/main/cpp/ComponentDescriptors.h +18 -0
- package/harmony/blurhash/src/main/cpp/EventEmitters.cpp +36 -0
- package/harmony/blurhash/src/main/cpp/EventEmitters.h +40 -0
- package/harmony/blurhash/src/main/cpp/Props.cpp +25 -0
- package/harmony/blurhash/src/main/cpp/Props.h +73 -0
- package/harmony/blurhash/src/main/cpp/RNBlurhashTurboModule.cpp +42 -0
- package/harmony/blurhash/src/main/cpp/RNBlurhashTurboModule.h +19 -0
- package/harmony/blurhash/src/main/cpp/ShadowNodes.cpp +15 -0
- package/harmony/blurhash/src/main/cpp/ShadowNodes.h +27 -0
- package/harmony/blurhash/src/main/cpp/SparseArray.cpp +28 -0
- package/harmony/blurhash/src/main/cpp/SparseArray.h +26 -0
- package/harmony/blurhash/src/main/cpp/napi_init.cpp +68 -0
- package/harmony/blurhash/src/main/cpp/stb_image.h +7656 -0
- package/harmony/blurhash/src/main/cpp/stb_image_write.h +1724 -0
- package/harmony/blurhash/src/main/cpp/types/libblurhash/Index.d.ts +1 -0
- package/harmony/blurhash/src/main/cpp/types/libblurhash/oh-package.json5 +6 -0
- package/harmony/blurhash/src/main/ets/BlurhashPackage.ts +58 -0
- package/harmony/blurhash/src/main/ets/BlurhashTurboModule.ts +49 -0
- package/harmony/blurhash/src/main/ets/BlurhashView.ets +107 -0
- package/harmony/blurhash/src/main/ets/Logger.ts +64 -0
- package/harmony/blurhash/src/main/ets/RNCBlurhashView.ts +157 -0
- package/harmony/blurhash/src/main/ets/RNCSpecs.ts +163 -0
- package/harmony/blurhash/src/main/ets/TMSpecs.ts +33 -0
- package/harmony/blurhash/src/main/module.json5 +7 -0
- package/harmony/blurhash/src/main/resources/base/element/string.json +8 -0
- package/harmony/blurhash/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/blurhash/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/blurhash/ts.ts +26 -0
- package/harmony/blurhash.har +0 -0
- package/lib/commonjs/index.js +95 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/specs/NativeBlurhashModule.js +9 -0
- package/lib/commonjs/specs/NativeBlurhashModule.js.map +1 -0
- package/lib/commonjs/specs/NativeBlurhashView.js +10 -0
- package/lib/commonjs/specs/NativeBlurhashView.js.map +1 -0
- package/lib/commonjs/utils.js +56 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/index.js +85 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/NativeBlurhashModule.js +3 -0
- package/lib/module/specs/NativeBlurhashModule.js.map +1 -0
- package/lib/module/specs/NativeBlurhashView.js +3 -0
- package/lib/module/specs/NativeBlurhashView.js.map +1 -0
- package/lib/module/utils.js +48 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/index.d.ts +90 -0
- package/lib/typescript/specs/NativeBlurhashModule.d.ts +9 -0
- package/lib/typescript/specs/NativeBlurhashView.d.ts +19 -0
- package/lib/typescript/utils.d.ts +22 -0
- package/package.json +113 -0
- package/react-native-blurhash.podspec +34 -0
- package/src/index.tsx +131 -0
- package/src/specs/NativeBlurhashModule.ts +9 -0
- package/src/specs/NativeBlurhashView.ts +19 -0
- package/src/utils.ts +147 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const getEncode: (filename: String, components_x: Number, components_y: Number) => string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import type {
|
|
27
|
+
TurboModule,
|
|
28
|
+
TurboModuleContext,
|
|
29
|
+
DescriptorWrapperFactoryByDescriptorTypeCtx,
|
|
30
|
+
DescriptorWrapperFactoryByDescriptorType,
|
|
31
|
+
} from '@rnoh/react-native-openharmony/ts';
|
|
32
|
+
import { RNBlurhashModule } from './BlurhashTurboModule';
|
|
33
|
+
import { BlurhashModule } from './TMSpecs'
|
|
34
|
+
import { BlurhashView} from './RNCSpecs'
|
|
35
|
+
|
|
36
|
+
class BlurhashTurboModulesFactory extends TurboModulesFactory {
|
|
37
|
+
createTurboModule(name: string): TurboModule | null {
|
|
38
|
+
if (name === BlurhashModule.NAME) {
|
|
39
|
+
return new RNBlurhashModule(this.ctx);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
hasTurboModule(name: string): boolean {
|
|
45
|
+
return name === BlurhashModule.NAME;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class BlurhashPackage extends RNPackage {
|
|
50
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
51
|
+
return new BlurhashTurboModulesFactory(ctx);
|
|
52
|
+
}
|
|
53
|
+
createDescriptorWrapperFactoryByDescriptorType(ctx: DescriptorWrapperFactoryByDescriptorTypeCtx): DescriptorWrapperFactoryByDescriptorType {
|
|
54
|
+
return {
|
|
55
|
+
[BlurhashView.NAME]: (ctx) => new BlurhashView.DescriptorWrapper(ctx.descriptor)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { TurboModule, RNOHError, Tag } from '@rnoh/react-native-openharmony/ts';
|
|
26
|
+
import Logger from './Logger'
|
|
27
|
+
import { BlurhashModule } from "./TMSpecs"
|
|
28
|
+
import { ImageLoaderTurboModule } from '@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage/turboModules';
|
|
29
|
+
import { RemoteImageLoader } from '@rnoh/react-native-openharmony/src/main/ets/RemoteImageLoader';
|
|
30
|
+
|
|
31
|
+
import rnKeysCPPLib from 'librnoh_blurhash.so';
|
|
32
|
+
|
|
33
|
+
export class RNBlurhashModule extends TurboModule implements BlurhashModule.Spec {
|
|
34
|
+
clearCosineCache(): void {
|
|
35
|
+
Logger.debug('[RNOH]:BlurhashModule call clearCosineCache');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async createBlurhashFromImage(imageUri: string, componentsX: number, componentsY: number): Promise<string> {
|
|
39
|
+
const imageLoader = this.ctx.rnInstance.getTurboModule<ImageLoaderTurboModule>("ImageLoader");
|
|
40
|
+
const RemoteImageLoader = this.ctx.rnInstance.getTurboModule<RemoteImageLoader>("ImageLoader");
|
|
41
|
+
await imageLoader.prefetchImage(imageUri)
|
|
42
|
+
const filePath = RemoteImageLoader.getPrefetchResult(imageUri)
|
|
43
|
+
const fileName = filePath.split('/').pop();
|
|
44
|
+
const blurhashcode = rnKeysCPPLib.getEncode(fileName,componentsX,componentsY)
|
|
45
|
+
return (blurhashcode);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
//
|
|
25
|
+
// import {
|
|
26
|
+
// Descriptor,
|
|
27
|
+
// ViewBaseProps,
|
|
28
|
+
// RNViewBase,
|
|
29
|
+
// RNComponentContext
|
|
30
|
+
// } from '@rnoh/react-native-openharmony';
|
|
31
|
+
// // import { RNC } from "@rnoh/react-native-openharmony/generated";
|
|
32
|
+
// import { RNCBlurhashView } from './RNCBlurhashView'
|
|
33
|
+
// import Logger from './Logger';
|
|
34
|
+
//
|
|
35
|
+
//
|
|
36
|
+
// interface BlurhashViewProps extends ViewBaseProps {
|
|
37
|
+
// size: number
|
|
38
|
+
// }
|
|
39
|
+
//
|
|
40
|
+
// export type BlurhashViewDescriptor = Descriptor<"BlurhashView", BlurhashViewProps>
|
|
41
|
+
//
|
|
42
|
+
// @Component
|
|
43
|
+
// export struct BlurhashView {
|
|
44
|
+
// public static readonly NAME = "BlurhashView"
|
|
45
|
+
// public ctx!: RNComponentContext
|
|
46
|
+
// public tag: number = 0
|
|
47
|
+
// // @State descriptor: BlurhashViewDescriptor = {} as BlurhashViewDescriptor
|
|
48
|
+
// @State private descriptorWrapper: RNCBlurhashView.DescriptorWrapper = {} as RNCBlurhashView.DescriptorWrapper;
|
|
49
|
+
// @State fontSize: number | undefined = undefined
|
|
50
|
+
// private cleanUpCallbacks: (() => void)[] = []
|
|
51
|
+
// private eventEmitter: RNCBlurhashView.EventEmitter | undefined = undefined
|
|
52
|
+
//
|
|
53
|
+
// aboutToAppear() {
|
|
54
|
+
// // this.descriptor = this.ctx.descriptorRegistry.getDescriptor<BlurhashViewDescriptor>(this.tag)
|
|
55
|
+
// // this.cleanUpCallbacks.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
|
|
56
|
+
// // (newDescriptor) => {
|
|
57
|
+
// // this.descriptor = (newDescriptor as BlurhashViewDescriptor)
|
|
58
|
+
// // }
|
|
59
|
+
// // ))
|
|
60
|
+
// // this.cleanUpCallbacks.push(this.ctx.componentCommandReceiver.registerCommandCallback(this.tag, (commandName) => {
|
|
61
|
+
// // if (commandName === "toggleFontSize") {
|
|
62
|
+
// // this.fontSize = this.fontSize ? undefined : 20
|
|
63
|
+
// // }
|
|
64
|
+
// // }))
|
|
65
|
+
// Logger.info('99999999999999999999')
|
|
66
|
+
// console.log('9999999999999999999911')
|
|
67
|
+
// this.eventEmitter = new RNCBlurhashView.EventEmitter(this.ctx.rnInstance, this.tag)
|
|
68
|
+
// this.onDescriptorWrapperChange(this.ctx.descriptorRegistry.findDescriptorWrapperByTag<RNCBlurhashView.DescriptorWrapper>(this.tag)!);
|
|
69
|
+
// this.cleanUpCallbacks.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
|
|
70
|
+
// (_descriptor, newDescriptorWrapper) => {
|
|
71
|
+
// this.onDescriptorWrapperChange(newDescriptorWrapper! as RNCBlurhashView.DescriptorWrapper)
|
|
72
|
+
// }
|
|
73
|
+
// ))
|
|
74
|
+
// this.descriptorWrapper.props
|
|
75
|
+
// }
|
|
76
|
+
//
|
|
77
|
+
// private onDescriptorWrapperChange(descriptorWrapper: RNCBlurhashView.DescriptorWrapper) {
|
|
78
|
+
// this.descriptorWrapper = descriptorWrapper;
|
|
79
|
+
// }
|
|
80
|
+
//
|
|
81
|
+
// aboutToDisappear() {
|
|
82
|
+
// this.cleanUpCallbacks.forEach(cb => cb())
|
|
83
|
+
// }
|
|
84
|
+
//
|
|
85
|
+
// build() {
|
|
86
|
+
// RNViewBase({ ctx: this.ctx, tag: this.tag }) {
|
|
87
|
+
// Text(this.descriptorWrapper.tag.toString()).fontColor("white").fontSize(this.fontSize ?? 12)
|
|
88
|
+
// this.ctx.wrappedRNChildrenBuilder.builder(this.ctx, this.tag)
|
|
89
|
+
// }
|
|
90
|
+
// }
|
|
91
|
+
//
|
|
92
|
+
// onLoadStart() {
|
|
93
|
+
// Logger.info('RNOH component onLoadStart 11111111')
|
|
94
|
+
// this.eventEmitter!.emit("loadStart", {})
|
|
95
|
+
// }
|
|
96
|
+
//
|
|
97
|
+
// onError() {
|
|
98
|
+
// Logger.error(`RNOH in RNBlurhash onError,${this.tag}`);
|
|
99
|
+
// this.eventEmitter!.emit("loadError", {})
|
|
100
|
+
// }
|
|
101
|
+
//
|
|
102
|
+
// onLoadEnd() {
|
|
103
|
+
// Logger.info('RNOH component onLoadEnd 22222222')
|
|
104
|
+
// this.eventEmitter!.emit("loadEnd", {})
|
|
105
|
+
// }
|
|
106
|
+
//
|
|
107
|
+
// }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import hilog from '@ohos.hilog';
|
|
26
|
+
|
|
27
|
+
class Logger {
|
|
28
|
+
private domain: number;
|
|
29
|
+
private prefix: string;
|
|
30
|
+
private format: string = '%{public}s, %{public}s';
|
|
31
|
+
private isDebug: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* constructor.
|
|
35
|
+
*
|
|
36
|
+
* @param Prefix Identifies the log tag.
|
|
37
|
+
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
|
|
38
|
+
*/
|
|
39
|
+
constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
|
|
40
|
+
this.prefix = prefix;
|
|
41
|
+
this.domain = domain;
|
|
42
|
+
this.isDebug = isDebug;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
debug(...args: string[]): void {
|
|
46
|
+
if (this.isDebug) {
|
|
47
|
+
hilog.debug(this.domain, this.prefix, this.format, args);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
info(...args: string[]): void {
|
|
52
|
+
hilog.info(this.domain, this.prefix, this.format, args);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
warn(...args: string[]): void {
|
|
56
|
+
hilog.warn(this.domain, this.prefix, this.format, args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
error(...args: string[]): void {
|
|
60
|
+
hilog.error(this.domain, this.prefix, this.format, args);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default new Logger('RNBlurhash', 0xFF00, false)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
Descriptor as ComponentDescriptor,
|
|
27
|
+
ViewBaseProps,
|
|
28
|
+
ViewRawProps,
|
|
29
|
+
ViewDescriptorWrapperBase,
|
|
30
|
+
ColorValue,
|
|
31
|
+
Color,
|
|
32
|
+
RNInstance,
|
|
33
|
+
Tag,
|
|
34
|
+
RNComponentCommandReceiver,
|
|
35
|
+
ViewPropsSelector,
|
|
36
|
+
} from '@rnoh/react-native-openharmony/ts';
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export namespace RNCBlurhashView {
|
|
40
|
+
export const NAME = "RNCBlurhashView" as const
|
|
41
|
+
|
|
42
|
+
export interface DirectRawProps {
|
|
43
|
+
blurhash: string;
|
|
44
|
+
decodeWidth?: number;
|
|
45
|
+
decodeHeight?: number;
|
|
46
|
+
decodePunch?: number;
|
|
47
|
+
decodeAsync?: boolean;
|
|
48
|
+
resizeMode?: 'cover' | 'contain' | 'stretch' | 'center';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface Props extends ViewBaseProps {}
|
|
52
|
+
|
|
53
|
+
export interface State {}
|
|
54
|
+
|
|
55
|
+
export interface RawProps extends ViewRawProps, DirectRawProps {}
|
|
56
|
+
|
|
57
|
+
export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
|
|
58
|
+
get blurhash() {
|
|
59
|
+
return this.rawProps.blurhash;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get decodeWidth() {
|
|
63
|
+
return this.rawProps.decodeWidth ?? 32;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get decodeHeight() {
|
|
67
|
+
return this.rawProps.decodeHeight ?? 32;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get decodePunch() {
|
|
71
|
+
return this.rawProps.decodePunch ?? 1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get decodeAsync() {
|
|
75
|
+
return this.rawProps.decodeAsync ?? false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get resizeMode() {
|
|
79
|
+
return this.rawProps.resizeMode ?? 'cover';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type Descriptor = ComponentDescriptor<
|
|
86
|
+
typeof NAME,
|
|
87
|
+
Props,
|
|
88
|
+
State,
|
|
89
|
+
RawProps
|
|
90
|
+
>;
|
|
91
|
+
|
|
92
|
+
export class DescriptorWrapper extends ViewDescriptorWrapperBase<
|
|
93
|
+
typeof NAME,
|
|
94
|
+
Props,
|
|
95
|
+
State,
|
|
96
|
+
RawProps,
|
|
97
|
+
PropsSelector
|
|
98
|
+
> {
|
|
99
|
+
protected createPropsSelector() {
|
|
100
|
+
return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface EventPayloadByName {
|
|
105
|
+
"loadStart": {}
|
|
106
|
+
"loadEnd": {}
|
|
107
|
+
"loadError": {message?: string}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class EventEmitter {
|
|
111
|
+
constructor(private rnInstance: RNInstance, private tag: Tag) {}
|
|
112
|
+
|
|
113
|
+
emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
|
|
114
|
+
this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface CommandArgvByName {
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export class CommandReceiver {
|
|
122
|
+
private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
|
|
123
|
+
private cleanUp: (() => void) | undefined = undefined
|
|
124
|
+
|
|
125
|
+
constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
|
|
129
|
+
if (!this.listenersByCommandName.has(commandName)) {
|
|
130
|
+
this.listenersByCommandName.set(commandName, new Set())
|
|
131
|
+
}
|
|
132
|
+
this.listenersByCommandName.get(commandName)!.add(listener)
|
|
133
|
+
const hasRegisteredCommandReceiver = !!this.cleanUp
|
|
134
|
+
if (!hasRegisteredCommandReceiver) {
|
|
135
|
+
this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => {
|
|
136
|
+
if (this.listenersByCommandName.has(commandName)) {
|
|
137
|
+
const listeners = this.listenersByCommandName.get(commandName)!
|
|
138
|
+
listeners.forEach(listener => {
|
|
139
|
+
listener(argv)
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return () => {
|
|
146
|
+
this.listenersByCommandName.get(commandName)?.delete(listener)
|
|
147
|
+
if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
|
|
148
|
+
this.listenersByCommandName.delete(commandName)
|
|
149
|
+
}
|
|
150
|
+
if (this.listenersByCommandName.size === 0) {
|
|
151
|
+
this.cleanUp?.()
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
Descriptor as ComponentDescriptor,
|
|
27
|
+
ViewBaseProps,
|
|
28
|
+
ViewRawProps,
|
|
29
|
+
ViewDescriptorWrapperBase,
|
|
30
|
+
RNInstance,
|
|
31
|
+
Tag,
|
|
32
|
+
RNComponentCommandReceiver,
|
|
33
|
+
ViewPropsSelector,
|
|
34
|
+
} from '@rnoh/react-native-openharmony/ts';
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export namespace BlurhashView {
|
|
38
|
+
export const NAME = "BlurhashView" as const
|
|
39
|
+
|
|
40
|
+
export interface DirectRawProps {
|
|
41
|
+
blurhash:string;
|
|
42
|
+
decodeWidth?:number;
|
|
43
|
+
decodeHeight?:number;
|
|
44
|
+
decodePunch?:number;
|
|
45
|
+
decodeAsync?:boolean;
|
|
46
|
+
resizeMode?: 'contain' | 'cover' | 'stretch' | 'center';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface Props extends ViewBaseProps {}
|
|
50
|
+
|
|
51
|
+
export interface State {}
|
|
52
|
+
|
|
53
|
+
export interface RawProps extends ViewRawProps, DirectRawProps {}
|
|
54
|
+
|
|
55
|
+
export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
|
|
56
|
+
|
|
57
|
+
get blurhash() {
|
|
58
|
+
console.log(this.blurhash)
|
|
59
|
+
return this.blurhash;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get decodeWidth() {
|
|
63
|
+
console.log(this.decodeWidth)
|
|
64
|
+
return this.decodeWidth;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get decodeHeight() {
|
|
68
|
+
console.log(this.decodeHeight)
|
|
69
|
+
return this.decodeHeight;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get decodePunch() {
|
|
73
|
+
console.log(this.decodePunch)
|
|
74
|
+
return this.decodePunch;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get decodeAsync() {
|
|
78
|
+
console.log(this.decodeAsync)
|
|
79
|
+
return this.decodeAsync;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get resizeMode() {
|
|
83
|
+
console.log(this.resizeMode)
|
|
84
|
+
return this.rawProps.resizeMode ?? 'cover';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type Descriptor = ComponentDescriptor<
|
|
90
|
+
typeof NAME,
|
|
91
|
+
Props,
|
|
92
|
+
State,
|
|
93
|
+
RawProps
|
|
94
|
+
>;
|
|
95
|
+
|
|
96
|
+
export class DescriptorWrapper extends ViewDescriptorWrapperBase<
|
|
97
|
+
typeof NAME,
|
|
98
|
+
Props,
|
|
99
|
+
State,
|
|
100
|
+
RawProps,
|
|
101
|
+
PropsSelector
|
|
102
|
+
> {
|
|
103
|
+
protected createPropsSelector() {
|
|
104
|
+
return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface EventPayloadByName {
|
|
109
|
+
"Error": {}
|
|
110
|
+
"Load": {width: number, height: number}
|
|
111
|
+
"LoadEnd": {}
|
|
112
|
+
"LoadStart": {}
|
|
113
|
+
"Progress": {loaded: number, total: number}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export class EventEmitter {
|
|
117
|
+
constructor(private rnInstance: RNInstance, private tag: Tag) {}
|
|
118
|
+
|
|
119
|
+
emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
|
|
120
|
+
this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface CommandArgvByName {
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export class CommandReceiver {
|
|
128
|
+
private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
|
|
129
|
+
private cleanUp: (() => void) | undefined = undefined
|
|
130
|
+
|
|
131
|
+
constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
|
|
135
|
+
if (!this.listenersByCommandName.has(commandName)) {
|
|
136
|
+
this.listenersByCommandName.set(commandName, new Set())
|
|
137
|
+
}
|
|
138
|
+
this.listenersByCommandName.get(commandName)!.add(listener)
|
|
139
|
+
const hasRegisteredCommandReceiver = !!this.cleanUp
|
|
140
|
+
if (!hasRegisteredCommandReceiver) {
|
|
141
|
+
this.cleanUp = this.componentCommandReceiver.registerCommandCallback(this.tag, (commandName: string, argv: any[]) => {
|
|
142
|
+
if (this.listenersByCommandName.has(commandName)) {
|
|
143
|
+
const listeners = this.listenersByCommandName.get(commandName)!
|
|
144
|
+
listeners.forEach(listener => {
|
|
145
|
+
listener(argv)
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return () => {
|
|
152
|
+
this.listenersByCommandName.get(commandName)?.delete(listener)
|
|
153
|
+
if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
|
|
154
|
+
this.listenersByCommandName.delete(commandName)
|
|
155
|
+
}
|
|
156
|
+
if (this.listenersByCommandName.size === 0) {
|
|
157
|
+
this.cleanUp?.()
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export namespace BlurhashModule {
|
|
26
|
+
export const NAME = 'BlurhashModule' as const
|
|
27
|
+
|
|
28
|
+
export interface Spec {
|
|
29
|
+
createBlurhashFromImage(imageUri: string, componentsX: number, componentsY: number): Promise<string>;
|
|
30
|
+
|
|
31
|
+
clearCosineCache(): void;
|
|
32
|
+
}
|
|
33
|
+
}
|