react-native-unistyles 3.5.2 → 3.6.0
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/README.md +3 -0
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +44 -7
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +1 -1
- package/cxx/converters/BackgroundImageConverter.cpp +198 -11
- package/cxx/converters/BackgroundImageConverter.h +1 -0
- package/cxx/core/HostUnistyle.cpp +6 -0
- package/cxx/core/UnistylesRegistry.cpp +5 -5
- package/cxx/core/UnistylesRegistry.h +3 -3
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +53 -14
- package/cxx/hybridObjects/HybridShadowRegistry.h +3 -2
- package/cxx/hybridObjects/HybridStyleSheet.cpp +3 -3
- package/cxx/parser/Parser.cpp +47 -9
- package/cxx/shadowTree/ShadowTreeManager.cpp +5 -5
- package/cxx/shadowTree/ShadowTreeManager.h +1 -1
- package/ios/NativePlatform+ios.swift +28 -15
- package/ios/NativePlatformListener+ios.swift +9 -0
- package/lib/commonjs/components/native/deep/ActivityIndicator.js +19 -0
- package/lib/commonjs/components/native/deep/ActivityIndicator.js.map +1 -0
- package/lib/commonjs/components/native/deep/Animated.js +19 -0
- package/lib/commonjs/components/native/deep/Animated.js.map +1 -0
- package/lib/commonjs/components/native/deep/FlatList.js +19 -0
- package/lib/commonjs/components/native/deep/FlatList.js.map +1 -0
- package/lib/commonjs/components/native/deep/Image.js +19 -0
- package/lib/commonjs/components/native/deep/Image.js.map +1 -0
- package/lib/commonjs/components/native/deep/ImageBackground.js +19 -0
- package/lib/commonjs/components/native/deep/ImageBackground.js.map +1 -0
- package/lib/commonjs/components/native/deep/KeyboardAvoidingView.js +19 -0
- package/lib/commonjs/components/native/deep/KeyboardAvoidingView.js.map +1 -0
- package/lib/commonjs/components/native/deep/Pressable.js +19 -0
- package/lib/commonjs/components/native/deep/Pressable.js.map +1 -0
- package/lib/commonjs/components/native/deep/RefreshControl.js +19 -0
- package/lib/commonjs/components/native/deep/RefreshControl.js.map +1 -0
- package/lib/commonjs/components/native/deep/SafeAreaView.js +19 -0
- package/lib/commonjs/components/native/deep/SafeAreaView.js.map +1 -0
- package/lib/commonjs/components/native/deep/ScrollView.js +19 -0
- package/lib/commonjs/components/native/deep/ScrollView.js.map +1 -0
- package/lib/commonjs/components/native/deep/SectionList.js +19 -0
- package/lib/commonjs/components/native/deep/SectionList.js.map +1 -0
- package/lib/commonjs/components/native/deep/Switch.js +19 -0
- package/lib/commonjs/components/native/deep/Switch.js.map +1 -0
- package/lib/commonjs/components/native/deep/Text.js +19 -0
- package/lib/commonjs/components/native/deep/Text.js.map +1 -0
- package/lib/commonjs/components/native/deep/TextInput.js +19 -0
- package/lib/commonjs/components/native/deep/TextInput.js.map +1 -0
- package/lib/commonjs/components/native/deep/TextNativeComponent.js +28 -0
- package/lib/commonjs/components/native/deep/TextNativeComponent.js.map +1 -0
- package/lib/commonjs/components/native/deep/TouchableHighlight.js +19 -0
- package/lib/commonjs/components/native/deep/TouchableHighlight.js.map +1 -0
- package/lib/commonjs/components/native/deep/TouchableOpacity.js +19 -0
- package/lib/commonjs/components/native/deep/TouchableOpacity.js.map +1 -0
- package/lib/commonjs/components/native/deep/View.js +19 -0
- package/lib/commonjs/components/native/deep/View.js.map +1 -0
- package/lib/commonjs/components/native/deep/ViewNativeComponent.js +26 -0
- package/lib/commonjs/components/native/deep/ViewNativeComponent.js.map +1 -0
- package/lib/commonjs/components/native/deep/VirtualizedList.js +19 -0
- package/lib/commonjs/components/native/deep/VirtualizedList.js.map +1 -0
- package/lib/commonjs/components/native/index.js +43 -0
- package/lib/commonjs/components/native/index.js.map +1 -0
- package/lib/commonjs/core/createUnistylesActivityIndicator.js +13 -3
- package/lib/commonjs/core/createUnistylesActivityIndicator.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +6 -0
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +20 -17
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/createUnistylesTouchableHighlight.js +6 -0
- package/lib/commonjs/core/createUnistylesTouchableHighlight.js.map +1 -1
- package/lib/commonjs/core/getClassname.js +15 -0
- package/lib/commonjs/core/getClassname.js.map +1 -1
- package/lib/commonjs/core/hasUnistyles.js +26 -0
- package/lib/commonjs/core/hasUnistyles.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +10 -0
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +16 -15
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +86 -110
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/styleSource.js +65 -0
- package/lib/commonjs/specs/ShadowRegistry/styleSource.js.map +1 -0
- package/lib/commonjs/unifiber/src/adapters/reanimated.js +157 -0
- package/lib/commonjs/unifiber/src/adapters/reanimated.js.map +1 -0
- package/lib/commonjs/unifiber/src/adapters/registry.js +67 -0
- package/lib/commonjs/unifiber/src/adapters/registry.js.map +1 -0
- package/lib/commonjs/unifiber/src/diagnostics.js +59 -0
- package/lib/commonjs/unifiber/src/diagnostics.js.map +1 -0
- package/lib/commonjs/unifiber/src/fiber.js +199 -0
- package/lib/commonjs/unifiber/src/fiber.js.map +1 -0
- package/lib/commonjs/unifiber/src/host.js +214 -0
- package/lib/commonjs/unifiber/src/host.js.map +1 -0
- package/lib/commonjs/unifiber/src/index.js +38 -0
- package/lib/commonjs/unifiber/src/index.js.map +1 -0
- package/lib/commonjs/web/css/core.js +30 -5
- package/lib/commonjs/web/css/core.js.map +1 -1
- package/lib/commonjs/web/css/state.js +4 -1
- package/lib/commonjs/web/css/state.js.map +1 -1
- package/lib/commonjs/web/registry.js +1 -1
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +11 -3
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/module/components/native/deep/ActivityIndicator.js +5 -0
- package/lib/module/components/native/deep/ActivityIndicator.js.map +1 -0
- package/lib/module/components/native/deep/Animated.js +5 -0
- package/lib/module/components/native/deep/Animated.js.map +1 -0
- package/lib/module/components/native/deep/FlatList.js +5 -0
- package/lib/module/components/native/deep/FlatList.js.map +1 -0
- package/lib/module/components/native/deep/Image.js +5 -0
- package/lib/module/components/native/deep/Image.js.map +1 -0
- package/lib/module/components/native/deep/ImageBackground.js +5 -0
- package/lib/module/components/native/deep/ImageBackground.js.map +1 -0
- package/lib/module/components/native/deep/KeyboardAvoidingView.js +5 -0
- package/lib/module/components/native/deep/KeyboardAvoidingView.js.map +1 -0
- package/lib/module/components/native/deep/Pressable.js +5 -0
- package/lib/module/components/native/deep/Pressable.js.map +1 -0
- package/lib/module/components/native/deep/RefreshControl.js +5 -0
- package/lib/module/components/native/deep/RefreshControl.js.map +1 -0
- package/lib/module/components/native/deep/SafeAreaView.js +5 -0
- package/lib/module/components/native/deep/SafeAreaView.js.map +1 -0
- package/lib/module/components/native/deep/ScrollView.js +5 -0
- package/lib/module/components/native/deep/ScrollView.js.map +1 -0
- package/lib/module/components/native/deep/SectionList.js +5 -0
- package/lib/module/components/native/deep/SectionList.js.map +1 -0
- package/lib/module/components/native/deep/Switch.js +5 -0
- package/lib/module/components/native/deep/Switch.js.map +1 -0
- package/lib/module/components/native/deep/Text.js +5 -0
- package/lib/module/components/native/deep/Text.js.map +1 -0
- package/lib/module/components/native/deep/TextInput.js +5 -0
- package/lib/module/components/native/deep/TextInput.js.map +1 -0
- package/lib/module/components/native/deep/TextNativeComponent.js +8 -0
- package/lib/module/components/native/deep/TextNativeComponent.js.map +1 -0
- package/lib/module/components/native/deep/TouchableHighlight.js +5 -0
- package/lib/module/components/native/deep/TouchableHighlight.js.map +1 -0
- package/lib/module/components/native/deep/TouchableOpacity.js +5 -0
- package/lib/module/components/native/deep/TouchableOpacity.js.map +1 -0
- package/lib/module/components/native/deep/View.js +5 -0
- package/lib/module/components/native/deep/View.js.map +1 -0
- package/lib/module/components/native/deep/ViewNativeComponent.js +8 -0
- package/lib/module/components/native/deep/ViewNativeComponent.js.map +1 -0
- package/lib/module/components/native/deep/VirtualizedList.js +5 -0
- package/lib/module/components/native/deep/VirtualizedList.js.map +1 -0
- package/lib/module/components/native/index.js +43 -0
- package/lib/module/components/native/index.js.map +1 -0
- package/lib/module/core/createUnistylesActivityIndicator.js +13 -3
- package/lib/module/core/createUnistylesActivityIndicator.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +6 -0
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +20 -17
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/createUnistylesTouchableHighlight.js +6 -0
- package/lib/module/core/createUnistylesTouchableHighlight.js.map +1 -1
- package/lib/module/core/getClassname.js +16 -1
- package/lib/module/core/getClassname.js.map +1 -1
- package/lib/module/core/hasUnistyles.js +21 -0
- package/lib/module/core/hasUnistyles.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +10 -0
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +14 -14
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +86 -110
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/styleSource.js +60 -0
- package/lib/module/specs/ShadowRegistry/styleSource.js.map +1 -0
- package/lib/module/unifiber/src/adapters/reanimated.js +152 -0
- package/lib/module/unifiber/src/adapters/reanimated.js.map +1 -0
- package/lib/module/unifiber/src/adapters/registry.js +62 -0
- package/lib/module/unifiber/src/adapters/registry.js.map +1 -0
- package/lib/module/unifiber/src/diagnostics.js +52 -0
- package/lib/module/unifiber/src/diagnostics.js.map +1 -0
- package/lib/module/unifiber/src/fiber.js +183 -0
- package/lib/module/unifiber/src/fiber.js.map +1 -0
- package/lib/module/unifiber/src/host.js +191 -0
- package/lib/module/unifiber/src/host.js.map +1 -0
- package/lib/module/unifiber/src/index.js +33 -0
- package/lib/module/unifiber/src/index.js.map +1 -0
- package/lib/module/web/css/core.js +28 -4
- package/lib/module/web/css/core.js.map +1 -1
- package/lib/module/web/css/state.js +5 -2
- package/lib/module/web/css/state.js.map +1 -1
- package/lib/module/web/registry.js +1 -1
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +11 -3
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/typescript/src/components/native/deep/ActivityIndicator.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/ActivityIndicator.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/Animated.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/Animated.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/FlatList.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/FlatList.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/Image.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/Image.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/ImageBackground.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/ImageBackground.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/KeyboardAvoidingView.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/KeyboardAvoidingView.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/Pressable.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/Pressable.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/RefreshControl.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/RefreshControl.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/SafeAreaView.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/SafeAreaView.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/ScrollView.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/ScrollView.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/SectionList.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/SectionList.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/Switch.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/Switch.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/Text.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/Text.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/TextInput.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/TextInput.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/TextNativeComponent.d.ts +3 -0
- package/lib/typescript/src/components/native/deep/TextNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/TouchableHighlight.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/TouchableHighlight.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/TouchableOpacity.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/TouchableOpacity.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/View.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/View.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/ViewNativeComponent.d.ts +3 -0
- package/lib/typescript/src/components/native/deep/ViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/components/native/deep/VirtualizedList.d.ts +2 -0
- package/lib/typescript/src/components/native/deep/VirtualizedList.d.ts.map +1 -0
- package/lib/typescript/src/components/native/index.d.ts +4 -0
- package/lib/typescript/src/components/native/index.d.ts.map +1 -0
- package/lib/typescript/src/components/scopeChildren.d.ts +1 -1
- package/lib/typescript/src/core/createUnistylesActivityIndicator.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesTouchableHighlight.d.ts.map +1 -1
- package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
- package/lib/typescript/src/core/hasUnistyles.d.ts +2 -0
- package/lib/typescript/src/core/hasUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +6 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts +11 -0
- package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +4 -41
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
- package/lib/typescript/src/unifiber/src/adapters/reanimated.d.ts +17 -0
- package/lib/typescript/src/unifiber/src/adapters/reanimated.d.ts.map +1 -0
- package/lib/typescript/src/unifiber/src/adapters/registry.d.ts +23 -0
- package/lib/typescript/src/unifiber/src/adapters/registry.d.ts.map +1 -0
- package/lib/typescript/src/unifiber/src/diagnostics.d.ts +10 -0
- package/lib/typescript/src/unifiber/src/diagnostics.d.ts.map +1 -0
- package/lib/typescript/src/unifiber/src/fiber.d.ts +48 -0
- package/lib/typescript/src/unifiber/src/fiber.d.ts.map +1 -0
- package/lib/typescript/src/unifiber/src/host.d.ts +32 -0
- package/lib/typescript/src/unifiber/src/host.d.ts.map +1 -0
- package/lib/typescript/src/unifiber/src/index.d.ts +49 -0
- package/lib/typescript/src/unifiber/src/index.d.ts.map +1 -0
- package/lib/typescript/src/web/css/core.d.ts +1 -0
- package/lib/typescript/src/web/css/core.d.ts.map +1 -1
- package/lib/typescript/src/web/css/state.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/metro/babel-transformer.js +1040 -0
- package/metro/index.d.ts +31 -0
- package/metro/index.js +170 -0
- package/package.json +26 -8
- package/plugin/index.d.ts +7 -0
- package/plugin/index.js +36 -16
- package/src/components/native/deep/ActivityIndicator.ts +2 -0
- package/src/components/native/deep/Animated.ts +2 -0
- package/src/components/native/deep/FlatList.ts +2 -0
- package/src/components/native/deep/Image.ts +2 -0
- package/src/components/native/deep/ImageBackground.ts +2 -0
- package/src/components/native/deep/KeyboardAvoidingView.ts +2 -0
- package/src/components/native/deep/Pressable.ts +2 -0
- package/src/components/native/deep/RefreshControl.ts +2 -0
- package/src/components/native/deep/SafeAreaView.ts +2 -0
- package/src/components/native/deep/ScrollView.ts +2 -0
- package/src/components/native/deep/SectionList.ts +2 -0
- package/src/components/native/deep/Switch.ts +2 -0
- package/src/components/native/deep/Text.ts +2 -0
- package/src/components/native/deep/TextInput.ts +2 -0
- package/src/components/native/deep/TextNativeComponent.ts +5 -0
- package/src/components/native/deep/TouchableHighlight.ts +2 -0
- package/src/components/native/deep/TouchableOpacity.ts +2 -0
- package/src/components/native/deep/View.ts +2 -0
- package/src/components/native/deep/ViewNativeComponent.ts +5 -0
- package/src/components/native/deep/VirtualizedList.ts +2 -0
- package/src/components/native/index.ts +41 -0
- package/src/core/createUnistylesActivityIndicator.tsx +11 -4
- package/src/core/createUnistylesElement.native.tsx +5 -0
- package/src/core/createUnistylesImageBackground.tsx +27 -23
- package/src/core/createUnistylesTouchableHighlight.tsx +5 -0
- package/src/core/getClassname.ts +10 -1
- package/src/core/hasUnistyles.ts +20 -0
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +11 -0
- package/src/core/withUnistyles/withUnistyles.native.tsx +22 -25
- package/src/specs/ShadowRegistry/index.ts +87 -149
- package/src/specs/ShadowRegistry/styleSource.ts +78 -0
- package/src/specs/ShadowRegistry/types.ts +3 -43
- package/src/unifiber/LICENSE +21 -0
- package/src/unifiber/README.md +92 -0
- package/src/unifiber/src/adapters/reanimated.ts +204 -0
- package/src/unifiber/src/adapters/registry.ts +102 -0
- package/src/unifiber/src/diagnostics.ts +55 -0
- package/src/unifiber/src/fiber.ts +262 -0
- package/src/unifiber/src/host.ts +236 -0
- package/src/unifiber/src/index.ts +43 -0
- package/src/web/css/core.ts +29 -4
- package/src/web/css/state.ts +6 -2
- package/src/web/registry.ts +1 -1
- package/src/web/utils/unistyle.ts +12 -3
- package/lib/typescript/src/__tests__/mocks.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/mocks.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/passForwardRef.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/passForwardRef.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/web-listener.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/web-listener.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/web-runtime.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/web-runtime.spec.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -190,6 +190,9 @@ Looking for help or you want to chat with me?
|
|
|
190
190
|
|
|
191
191
|
[Join Discord](https://discord.gg/akGHf27P4C)
|
|
192
192
|
|
|
193
|
+
## Contributing
|
|
194
|
+
The repository uses a git submodule ([unifiber](https://github.com/uni-stack/unifiber)). Clone it with `git clone --recurse-submodules`, or run `git submodule update --init` in an existing clone.
|
|
195
|
+
|
|
193
196
|
|
|
194
197
|
## License
|
|
195
198
|
|
|
@@ -3,11 +3,16 @@ package com.unistyles
|
|
|
3
3
|
import android.os.Build
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.content.res.Configuration
|
|
6
|
+
import android.content.res.Resources
|
|
7
|
+
import android.os.Handler
|
|
8
|
+
import android.os.Looper
|
|
6
9
|
import android.util.DisplayMetrics
|
|
7
10
|
import android.view.View
|
|
8
11
|
import android.view.WindowManager
|
|
9
12
|
import androidx.annotation.Keep
|
|
13
|
+
import androidx.core.content.OnConfigurationChangedProvider
|
|
10
14
|
import androidx.core.text.TextUtilsCompat
|
|
15
|
+
import androidx.core.util.Consumer
|
|
11
16
|
import androidx.core.view.ViewCompat
|
|
12
17
|
import androidx.core.view.WindowCompat
|
|
13
18
|
import androidx.core.view.WindowInsetsCompat
|
|
@@ -22,6 +27,7 @@ import com.margelo.nitro.unistyles.Insets
|
|
|
22
27
|
import com.margelo.nitro.unistyles.Orientation
|
|
23
28
|
import com.margelo.nitro.unistyles.UnistyleDependency
|
|
24
29
|
import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
|
|
30
|
+
import java.lang.ref.WeakReference
|
|
25
31
|
import java.util.Locale
|
|
26
32
|
|
|
27
33
|
@Keep
|
|
@@ -30,6 +36,14 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
30
36
|
private val _insets = NativePlatformInsets(reactContext, this::getMiniRuntime) { this.onConfigChange() }
|
|
31
37
|
private var _miniRuntime: UnistylesNativeMiniRuntime = buildMiniRuntime()
|
|
32
38
|
private val _listener = NativePlatformListener(reactContext, this::getMiniRuntime) { this.diffMiniRuntime() }
|
|
39
|
+
private var _configurationProvider: WeakReference<OnConfigurationChangedProvider>? = null
|
|
40
|
+
private val _activityConfigurationListener = Consumer<Configuration> {
|
|
41
|
+
Handler(Looper.getMainLooper()).post { this.onConfigChange() }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Application resources can lag behind configuration changes
|
|
45
|
+
private val configurationResources: Resources
|
|
46
|
+
get() = reactContext.currentActivity?.resources ?: reactContext.resources
|
|
33
47
|
|
|
34
48
|
init {
|
|
35
49
|
checkEdgeToEdge()
|
|
@@ -37,12 +51,16 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
37
51
|
}
|
|
38
52
|
|
|
39
53
|
fun onDestroy() {
|
|
54
|
+
stopObservingActivityConfiguration()
|
|
40
55
|
_listener.onDestroy()
|
|
41
56
|
_insets.onDestroy()
|
|
42
57
|
reactContext.removeLifecycleEventListener(this)
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
override fun onHostResume() {
|
|
61
|
+
observeActivityConfiguration()
|
|
62
|
+
// catch configuration changes missed while no Activity was attached
|
|
63
|
+
onConfigChange()
|
|
46
64
|
_insets.getInitialInsets(false)
|
|
47
65
|
_insets.startInsetsListener()
|
|
48
66
|
}
|
|
@@ -51,7 +69,26 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
51
69
|
_insets.stopInsetsListener()
|
|
52
70
|
}
|
|
53
71
|
|
|
54
|
-
override fun onHostDestroy() {
|
|
72
|
+
override fun onHostDestroy() {
|
|
73
|
+
stopObservingActivityConfiguration()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private fun observeActivityConfiguration() {
|
|
77
|
+
val provider = reactContext.currentActivity as? OnConfigurationChangedProvider
|
|
78
|
+
|
|
79
|
+
if (_configurationProvider?.get() === provider) {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
stopObservingActivityConfiguration()
|
|
84
|
+
provider?.addOnConfigurationChangedListener(_activityConfigurationListener)
|
|
85
|
+
_configurationProvider = provider?.let { WeakReference(it) }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private fun stopObservingActivityConfiguration() {
|
|
89
|
+
_configurationProvider?.get()?.removeOnConfigurationChangedListener(_activityConfigurationListener)
|
|
90
|
+
_configurationProvider = null
|
|
91
|
+
}
|
|
55
92
|
|
|
56
93
|
override val memorySize: Long
|
|
57
94
|
get() = 0
|
|
@@ -61,7 +98,7 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
61
98
|
}
|
|
62
99
|
|
|
63
100
|
override fun getColorScheme(): ColorScheme {
|
|
64
|
-
val uiMode =
|
|
101
|
+
val uiMode = configurationResources.configuration.uiMode
|
|
65
102
|
|
|
66
103
|
val colorScheme = when (uiMode.and(Configuration.UI_MODE_NIGHT_MASK)) {
|
|
67
104
|
Configuration.UI_MODE_NIGHT_YES -> ColorScheme.DARK
|
|
@@ -73,15 +110,15 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
73
110
|
}
|
|
74
111
|
|
|
75
112
|
override fun getFontScale(): Double {
|
|
76
|
-
return
|
|
113
|
+
return configurationResources.configuration.fontScale.toDouble()
|
|
77
114
|
}
|
|
78
115
|
|
|
79
116
|
override fun getPixelRatio(): Double {
|
|
80
|
-
return
|
|
117
|
+
return configurationResources.displayMetrics.density.toDouble()
|
|
81
118
|
}
|
|
82
119
|
|
|
83
120
|
override fun getOrientation(): Orientation {
|
|
84
|
-
val orientation = when (
|
|
121
|
+
val orientation = when (configurationResources.configuration.orientation) {
|
|
85
122
|
Configuration.ORIENTATION_PORTRAIT -> Orientation.PORTRAIT
|
|
86
123
|
Configuration.ORIENTATION_LANDSCAPE -> Orientation.LANDSCAPE
|
|
87
124
|
else -> Orientation.PORTRAIT
|
|
@@ -122,7 +159,7 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
122
159
|
return Dimensions(screenWidth, screenHeight)
|
|
123
160
|
}
|
|
124
161
|
else -> {
|
|
125
|
-
val displayMetrics =
|
|
162
|
+
val displayMetrics = configurationResources.displayMetrics
|
|
126
163
|
|
|
127
164
|
reactContext.currentActivity?.windowManager?.currentWindowMetrics?.bounds?.let {
|
|
128
165
|
val boundsWidth = (it.width() / displayMetrics.density).toDouble()
|
|
@@ -157,7 +194,7 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
157
194
|
"com.facebook.react.modules.i18nmanager.I18nUtil",
|
|
158
195
|
Context.MODE_PRIVATE
|
|
159
196
|
)
|
|
160
|
-
val resourcesLocale =
|
|
197
|
+
val resourcesLocale = configurationResources.configuration.locales[0]
|
|
161
198
|
val hasForcedRtl = sharedPrefs.getBoolean("RCTI18nUtil_forceRTL", false)
|
|
162
199
|
// user preferences
|
|
163
200
|
val isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL
|
|
@@ -38,7 +38,7 @@ class NativePlatformInsets(
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
fun getInsets(): Insets {
|
|
41
|
-
val density = reactContext.resources.displayMetrics.density
|
|
41
|
+
val density = (reactContext.currentActivity?.resources ?: reactContext.resources).displayMetrics.density
|
|
42
42
|
|
|
43
43
|
return Insets(
|
|
44
44
|
this._insets.top / density,
|
|
@@ -1,17 +1,177 @@
|
|
|
1
1
|
#include "BackgroundImageConverter.h"
|
|
2
2
|
|
|
3
3
|
#include <algorithm>
|
|
4
|
+
#include <cxxreact/ReactNativeVersion.h>
|
|
5
|
+
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
#
|
|
7
|
+
// React Native 0.83 added a C++ CSS parser for background images. Without
|
|
8
|
+
// enableNativeCSSParsing, the native props parser only accepts the processed
|
|
9
|
+
// form (array of gradient objects), so strings are converted here on both
|
|
10
|
+
// platforms.
|
|
11
|
+
#if __has_include(<react/renderer/css/CSSBackgroundImage.h>)
|
|
12
|
+
#include <folly/Conv.h>
|
|
13
|
+
#include <react/renderer/css/CSSBackgroundImage.h>
|
|
14
|
+
#include <react/renderer/css/CSSValueParser.h>
|
|
10
15
|
#define UNISTYLES_HAS_RN_BACKGROUND_IMAGE_PARSER 1
|
|
11
16
|
#endif
|
|
12
17
|
|
|
13
18
|
namespace margelo::nitro::unistyles::converters {
|
|
14
19
|
|
|
20
|
+
#ifdef UNISTYLES_HAS_RN_BACKGROUND_IMAGE_PARSER
|
|
21
|
+
namespace {
|
|
22
|
+
|
|
23
|
+
using namespace facebook::react;
|
|
24
|
+
|
|
25
|
+
using CSSLengthPercentage = std::variant<CSSLength, CSSPercentage>;
|
|
26
|
+
using CSSGradientItems = std::vector<std::variant<CSSColorStop, CSSColorHint>>;
|
|
27
|
+
|
|
28
|
+
// same output as React Native's processBackgroundImage.js
|
|
29
|
+
folly::dynamic toPosition(const CSSLengthPercentage &value) {
|
|
30
|
+
if (std::holds_alternative<CSSLength>(value)) {
|
|
31
|
+
return std::get<CSSLength>(value).value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return folly::to<std::string>(std::get<CSSPercentage>(value).value) + "%";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ARGB, same as processColor
|
|
38
|
+
int32_t toColor(const CSSColor &color) {
|
|
39
|
+
return static_cast<int32_t>((static_cast<uint32_t>(color.a) << 24) |
|
|
40
|
+
(static_cast<uint32_t>(color.r) << 16) |
|
|
41
|
+
(static_cast<uint32_t>(color.g) << 8) |
|
|
42
|
+
static_cast<uint32_t>(color.b));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
folly::dynamic toColorStops(const CSSGradientItems &items) {
|
|
46
|
+
folly::dynamic colorStops = folly::dynamic::array();
|
|
47
|
+
|
|
48
|
+
for (const auto &item : items) {
|
|
49
|
+
if (std::holds_alternative<CSSColorHint>(item)) {
|
|
50
|
+
colorStops.push_back(folly::dynamic::object("color", nullptr)(
|
|
51
|
+
"position", toPosition(std::get<CSSColorHint>(item).position)));
|
|
52
|
+
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const auto &colorStop = std::get<CSSColorStop>(item);
|
|
57
|
+
auto color = toColor(colorStop.color);
|
|
58
|
+
|
|
59
|
+
colorStops.push_back(folly::dynamic::object("color", color)(
|
|
60
|
+
"position", colorStop.startPosition.has_value()
|
|
61
|
+
? toPosition(*colorStop.startPosition)
|
|
62
|
+
: nullptr));
|
|
63
|
+
|
|
64
|
+
if (colorStop.endPosition.has_value()) {
|
|
65
|
+
colorStops.push_back(folly::dynamic::object("color", color)(
|
|
66
|
+
"position", toPosition(*colorStop.endPosition)));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return colorStops;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::string toKeyword(CSSLinearGradientDirectionKeyword keyword) {
|
|
74
|
+
switch (keyword) {
|
|
75
|
+
case CSSLinearGradientDirectionKeyword::ToTopLeft:
|
|
76
|
+
return "to top left";
|
|
77
|
+
case CSSLinearGradientDirectionKeyword::ToTopRight:
|
|
78
|
+
return "to top right";
|
|
79
|
+
case CSSLinearGradientDirectionKeyword::ToBottomLeft:
|
|
80
|
+
return "to bottom left";
|
|
81
|
+
case CSSLinearGradientDirectionKeyword::ToBottomRight:
|
|
82
|
+
return "to bottom right";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return "to bottom right";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
folly::dynamic toLinearGradient(const CSSLinearGradientFunction &gradient) {
|
|
89
|
+
folly::dynamic direction =
|
|
90
|
+
folly::dynamic::object("type", "angle")("value", 180.0);
|
|
91
|
+
|
|
92
|
+
if (gradient.direction.has_value()) {
|
|
93
|
+
const auto &value = gradient.direction->value;
|
|
94
|
+
|
|
95
|
+
direction =
|
|
96
|
+
std::holds_alternative<CSSAngle>(value)
|
|
97
|
+
? folly::dynamic::object("type", "angle")(
|
|
98
|
+
"value", std::get<CSSAngle>(value).degrees)
|
|
99
|
+
: folly::dynamic::object("type", "keyword")(
|
|
100
|
+
"value",
|
|
101
|
+
toKeyword(std::get<CSSLinearGradientDirectionKeyword>(value)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return folly::dynamic::object("type", "linear-gradient")(
|
|
105
|
+
"direction", std::move(direction))("colorStops",
|
|
106
|
+
toColorStops(gradient.items));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
std::string toSizeKeyword(CSSRadialGradientSizeKeyword keyword) {
|
|
110
|
+
switch (keyword) {
|
|
111
|
+
case CSSRadialGradientSizeKeyword::ClosestSide:
|
|
112
|
+
return "closest-side";
|
|
113
|
+
case CSSRadialGradientSizeKeyword::ClosestCorner:
|
|
114
|
+
return "closest-corner";
|
|
115
|
+
case CSSRadialGradientSizeKeyword::FarthestSide:
|
|
116
|
+
return "farthest-side";
|
|
117
|
+
case CSSRadialGradientSizeKeyword::FarthestCorner:
|
|
118
|
+
return "farthest-corner";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return "farthest-corner";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
folly::dynamic toRadialGradient(const CSSRadialGradientFunction &gradient) {
|
|
125
|
+
folly::dynamic size = "farthest-corner";
|
|
126
|
+
folly::dynamic position = folly::dynamic::object("top", "50%")("left", "50%");
|
|
127
|
+
|
|
128
|
+
if (gradient.size.has_value()) {
|
|
129
|
+
const auto &value = *gradient.size;
|
|
130
|
+
|
|
131
|
+
if (std::holds_alternative<CSSRadialGradientSizeKeyword>(value)) {
|
|
132
|
+
size = toSizeKeyword(std::get<CSSRadialGradientSizeKeyword>(value));
|
|
133
|
+
} else {
|
|
134
|
+
const auto &explicitSize = std::get<CSSRadialGradientExplicitSize>(value);
|
|
135
|
+
|
|
136
|
+
size = folly::dynamic::object("x", toPosition(explicitSize.sizeX))(
|
|
137
|
+
"y", toPosition(explicitSize.sizeY));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (gradient.position.has_value()) {
|
|
142
|
+
const auto &value = *gradient.position;
|
|
143
|
+
|
|
144
|
+
position = folly::dynamic::object();
|
|
145
|
+
|
|
146
|
+
if (value.top.has_value()) {
|
|
147
|
+
position["top"] = toPosition(*value.top);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (value.bottom.has_value()) {
|
|
151
|
+
position["bottom"] = toPosition(*value.bottom);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (value.left.has_value()) {
|
|
155
|
+
position["left"] = toPosition(*value.left);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (value.right.has_value()) {
|
|
159
|
+
position["right"] = toPosition(*value.right);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
auto isCircle = gradient.shape.has_value() &&
|
|
164
|
+
*gradient.shape == CSSRadialGradientShape::Circle;
|
|
165
|
+
|
|
166
|
+
return folly::dynamic::object("type", "radial-gradient")(
|
|
167
|
+
"shape", isCircle ? "circle" : "ellipse")("size", std::move(size))(
|
|
168
|
+
"position", std::move(position))("colorStops",
|
|
169
|
+
toColorStops(gradient.items));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
} // namespace
|
|
173
|
+
#endif
|
|
174
|
+
|
|
15
175
|
bool isBackgroundImagePropName(const std::string &propertyName) {
|
|
16
176
|
return propertyName == "backgroundImage" ||
|
|
17
177
|
propertyName == "experimental_backgroundImage";
|
|
@@ -37,19 +197,46 @@ bool hasSafeBackgroundImageColorStops(const folly::dynamic &backgroundImages) {
|
|
|
37
197
|
std::optional<folly::dynamic>
|
|
38
198
|
parseBackgroundImageString(const std::string &backgroundImageString) {
|
|
39
199
|
#ifdef UNISTYLES_HAS_RN_BACKGROUND_IMAGE_PARSER
|
|
40
|
-
|
|
200
|
+
using namespace facebook::react;
|
|
201
|
+
|
|
202
|
+
auto maybeBackgroundImages =
|
|
203
|
+
parseCSSProperty<CSSBackgroundImageList>(backgroundImageString);
|
|
41
204
|
|
|
42
|
-
|
|
43
|
-
|
|
205
|
+
if (!std::holds_alternative<CSSBackgroundImageList>(maybeBackgroundImages)) {
|
|
206
|
+
return folly::dynamic::array();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
folly::dynamic backgroundImages = folly::dynamic::array();
|
|
44
210
|
|
|
45
|
-
auto
|
|
211
|
+
for (const auto &backgroundImage :
|
|
212
|
+
std::get<CSSBackgroundImageList>(maybeBackgroundImages)) {
|
|
213
|
+
if (std::holds_alternative<CSSLinearGradientFunction>(backgroundImage)) {
|
|
214
|
+
backgroundImages.push_back(
|
|
215
|
+
toLinearGradient(std::get<CSSLinearGradientFunction>(backgroundImage)));
|
|
216
|
+
} else if (std::holds_alternative<CSSRadialGradientFunction>(
|
|
217
|
+
backgroundImage)) {
|
|
218
|
+
backgroundImages.push_back(
|
|
219
|
+
toRadialGradient(std::get<CSSRadialGradientFunction>(backgroundImage)));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
46
222
|
|
|
47
|
-
return hasSafeBackgroundImageColorStops(
|
|
48
|
-
? std::move(
|
|
223
|
+
return hasSafeBackgroundImageColorStops(backgroundImages)
|
|
224
|
+
? std::move(backgroundImages)
|
|
49
225
|
: folly::dynamic::array();
|
|
50
226
|
#else
|
|
51
227
|
return std::nullopt;
|
|
52
228
|
#endif
|
|
53
229
|
}
|
|
54
230
|
|
|
231
|
+
// React Native parses background image strings natively since 0.83, but only
|
|
232
|
+
// with enableNativeCSSParsing. Otherwise its view props expect the processed
|
|
233
|
+
// array and read a string as no background image.
|
|
234
|
+
bool canReactNativeParseBackgroundImageString() {
|
|
235
|
+
#if REACT_NATIVE_VERSION_MAJOR > 0 || REACT_NATIVE_VERSION_MINOR >= 83
|
|
236
|
+
return facebook::react::ReactNativeFeatureFlags::enableNativeCSSParsing();
|
|
237
|
+
#else
|
|
238
|
+
return false;
|
|
239
|
+
#endif
|
|
240
|
+
}
|
|
241
|
+
|
|
55
242
|
} // namespace margelo::nitro::unistyles::converters
|
|
@@ -10,5 +10,6 @@ bool isBackgroundImagePropName(const std::string &propertyName);
|
|
|
10
10
|
bool hasSafeBackgroundImageColorStops(const folly::dynamic &backgroundImages);
|
|
11
11
|
std::optional<folly::dynamic>
|
|
12
12
|
parseBackgroundImageString(const std::string &backgroundImageString);
|
|
13
|
+
bool canReactNativeParseBackgroundImageString();
|
|
13
14
|
|
|
14
15
|
} // namespace margelo::nitro::unistyles::converters
|
|
@@ -19,6 +19,12 @@ std::vector<jsi::PropNameID> HostUnistyle::getPropertyNames(jsi::Runtime& rt) {
|
|
|
19
19
|
|
|
20
20
|
HostUnistyle::~HostUnistyle() {
|
|
21
21
|
if (this->_ownsStyleSheet) {
|
|
22
|
+
for (const auto& [_, unistyle] : this->_stylesheet->unistyles) {
|
|
23
|
+
if (unistyle->type == UnistyleType::DynamicFunction) {
|
|
24
|
+
std::static_pointer_cast<UnistyleDynamicFunction>(unistyle)->proxiedFunction.reset();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
22
28
|
this->_stylesheet->unistyles.clear();
|
|
23
29
|
}
|
|
24
30
|
}
|
|
@@ -407,7 +407,7 @@ core::UnistylesRegistry::OwnedState core::UnistylesRegistry::takeOwnedState() {
|
|
|
407
407
|
ownedState.styleSheets = std::exchange(this->_styleSheetRegistry, {});
|
|
408
408
|
ownedState.state = std::move(this->_state);
|
|
409
409
|
this->_scopedTheme = std::nullopt;
|
|
410
|
-
this->
|
|
410
|
+
this->_committedInstanceHandles.clear();
|
|
411
411
|
_nextStyleSheetTag.store(0);
|
|
412
412
|
|
|
413
413
|
return ownedState;
|
|
@@ -435,10 +435,10 @@ size_t core::UnistylesRegistry::getPendingUpdatesCount() {
|
|
|
435
435
|
});
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
-
void core::UnistylesRegistry::
|
|
439
|
-
this->
|
|
438
|
+
void core::UnistylesRegistry::setCommittedInstanceHandles(std::vector<InstanceHandle::Shared>&& instanceHandles) {
|
|
439
|
+
this->_committedInstanceHandles = std::move(instanceHandles);
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
-
std::vector<
|
|
443
|
-
return std::exchange(this->
|
|
442
|
+
std::vector<InstanceHandle::Shared> core::UnistylesRegistry::takeCommittedInstanceHandles() {
|
|
443
|
+
return std::exchange(this->_committedInstanceHandles, {});
|
|
444
444
|
}
|
|
@@ -70,8 +70,8 @@ struct UnistylesRegistry: public StyleSheetRegistry {
|
|
|
70
70
|
core::Unistyle::Shared getUnistyleById(std::string unistyleID);
|
|
71
71
|
std::vector<LinkedFamilySnapshot> getLinkedFamiliesSnapshot();
|
|
72
72
|
size_t getPendingUpdatesCount();
|
|
73
|
-
void
|
|
74
|
-
std::vector<
|
|
73
|
+
void setCommittedInstanceHandles(std::vector<InstanceHandle::Shared>&& instanceHandles);
|
|
74
|
+
std::vector<InstanceHandle::Shared> takeCommittedInstanceHandles();
|
|
75
75
|
|
|
76
76
|
// newest installed runtime owns the registry, generation 0 means no owner
|
|
77
77
|
// previous runtime's state is kept aside until it releases ownership, as it may still run JS
|
|
@@ -119,7 +119,7 @@ private:
|
|
|
119
119
|
std::unordered_map<int, std::shared_ptr<core::StyleSheet>> _styleSheetRegistry{};
|
|
120
120
|
std::unordered_map<const ShadowNodeFamily*, LinkedFamily> _shadowRegistry{};
|
|
121
121
|
size_t _sweepThreshold = MIN_SWEEP_THRESHOLD;
|
|
122
|
-
std::vector<
|
|
122
|
+
std::vector<InstanceHandle::Shared> _committedInstanceHandles{};
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
inline UnistylesRegistry& UnistylesRegistry::get() {
|
|
@@ -33,8 +33,7 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
|
33
33
|
try {
|
|
34
34
|
auto rawStyle = args[1].asObject(rt).asArray(rt).getValueAtIndex(rt, i);
|
|
35
35
|
auto rawStyleObj = rawStyle.getObject(rt);
|
|
36
|
-
auto
|
|
37
|
-
auto secrets = rawStyleObj.getProperty(rt, unistyleHashKeys.at(0).c_str()).asObject(rt);
|
|
36
|
+
auto secrets = getUnistyleSecrets(rt, rawStyleObj, unistyleWrappers[i]).value();
|
|
38
37
|
auto secretArguments = secrets.getProperty(rt, helpers::ARGUMENTS.c_str()).asObject(rt).asArray(rt);
|
|
39
38
|
|
|
40
39
|
arguments.push_back(helpers::parseDynamicFunctionArguments(rt, secretArguments));
|
|
@@ -65,15 +64,14 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
|
65
64
|
core::Unistyle::Shared& unistyle = unistyleWrappers[i];
|
|
66
65
|
auto rawStyle = args[1].asObject(rt).asArray(rt).getValueAtIndex(rt, i);
|
|
67
66
|
auto rawStyleObj = rawStyle.getObject(rt);
|
|
68
|
-
auto
|
|
67
|
+
auto secrets = getUnistyleSecrets(rt, rawStyleObj, unistyle);
|
|
69
68
|
core::Variants variants{};
|
|
70
69
|
|
|
71
|
-
if (
|
|
72
|
-
auto
|
|
73
|
-
auto hasVariants = secrets.hasProperty(rt, helpers::STYLESHEET_VARIANTS.c_str());
|
|
70
|
+
if (secrets.has_value()) {
|
|
71
|
+
auto rawVariants = secrets->getProperty(rt, helpers::STYLESHEET_VARIANTS.c_str());
|
|
74
72
|
|
|
75
|
-
if (
|
|
76
|
-
variants = helpers::variantsToPairs(rt,
|
|
73
|
+
if (rawVariants.isObject()) {
|
|
74
|
+
variants = helpers::variantsToPairs(rt, rawVariants.asObject(rt));
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
|
|
@@ -94,8 +92,18 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
|
94
92
|
|
|
95
93
|
// The shared cache can belong to another view by the time React attaches refs.
|
|
96
94
|
// Restore this view's arguments and variants before saving its native styles.
|
|
95
|
+
// An object style without variants is the same for every view, so it's reused unless it's stale (dirty).
|
|
97
96
|
if (!unistyleData->parsedStyle.has_value() && unistyle->parsedStyle.has_value()) {
|
|
98
|
-
|
|
97
|
+
auto isSharedStyle = unistyle->type == core::UnistyleType::Object &&
|
|
98
|
+
unistyle->styleKey != helpers::EXOTIC_STYLE_KEY &&
|
|
99
|
+
!unistyle->isDirty &&
|
|
100
|
+
!unistyle->rawValue.hasProperty(rt, "variants");
|
|
101
|
+
|
|
102
|
+
if (isSharedStyle) {
|
|
103
|
+
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
|
104
|
+
} else {
|
|
105
|
+
parser.rebuildUnistyleWithVariants(rt, unistyleData);
|
|
106
|
+
}
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
unistylesData.emplace_back(unistyleData);
|
|
@@ -131,6 +139,29 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
|
131
139
|
return jsi::Value::undefined();
|
|
132
140
|
}
|
|
133
141
|
|
|
142
|
+
// a style made by Unistyles keeps its secrets (variants, arguments) under the unistyle's id,
|
|
143
|
+
// reading it directly spares enumerating (and converting to strings) every prop of every linked style
|
|
144
|
+
std::optional<jsi::Object> HybridShadowRegistry::getUnistyleSecrets(jsi::Runtime& rt, jsi::Object& style, const core::Unistyle::Shared& unistyle) {
|
|
145
|
+
// inline and React Native styles have no secrets
|
|
146
|
+
if (unistyle->styleKey == helpers::EXOTIC_STYLE_KEY) {
|
|
147
|
+
return std::nullopt;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
auto secrets = style.getProperty(rt, unistyle->unid.c_str());
|
|
151
|
+
|
|
152
|
+
if (secrets.isObject()) {
|
|
153
|
+
return secrets.asObject(rt);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
auto unistyleHashKeys = core::getUnistylesHashKeys(rt, style);
|
|
157
|
+
|
|
158
|
+
if (unistyleHashKeys.size() != 1) {
|
|
159
|
+
return std::nullopt;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return style.getProperty(rt, unistyleHashKeys.at(0).c_str()).asObject(rt);
|
|
163
|
+
}
|
|
164
|
+
|
|
134
165
|
void HybridShadowRegistry::scheduleShadowTreeUpdate(jsi::Runtime& rt) {
|
|
135
166
|
if (this->_isShadowTreeUpdateScheduled->exchange(true)) {
|
|
136
167
|
return;
|
|
@@ -232,12 +263,20 @@ jsi::Value HybridShadowRegistry::verify(jsi::Runtime &rt, const jsi::Value &this
|
|
|
232
263
|
return shadow::ShadowTreeDiagnostics::verify(rt, this->_unistylesRuntime);
|
|
233
264
|
}
|
|
234
265
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
266
|
+
// the fibers React created the committed nodes with (weak, null once collected)
|
|
267
|
+
jsi::Value HybridShadowRegistry::takeCommittedInstanceHandles(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
268
|
+
// runtime was replaced, the handles belong to the next one
|
|
269
|
+
if (!this->_unistylesRuntime->ownsRegistry()) {
|
|
270
|
+
return jsi::Array(rt, 0);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
auto instanceHandles = core::UnistylesRegistry::get().takeCommittedInstanceHandles();
|
|
274
|
+
auto result = jsi::Array(rt, instanceHandles.size());
|
|
275
|
+
|
|
276
|
+
for (size_t i = 0; i < instanceHandles.size(); i++) {
|
|
277
|
+
auto& instanceHandle = instanceHandles[i];
|
|
238
278
|
|
|
239
|
-
|
|
240
|
-
result.setValueAtIndex(rt, i, jsi::Value(static_cast<double>(tags[i])));
|
|
279
|
+
result.setValueAtIndex(rt, i, instanceHandle ? instanceHandle->getInstanceHandle(rt) : jsi::Value::null());
|
|
241
280
|
}
|
|
242
281
|
|
|
243
282
|
return result;
|
|
@@ -44,7 +44,7 @@ struct HybridShadowRegistry: public HybridUnistylesShadowRegistrySpec {
|
|
|
44
44
|
const jsi::Value& thisValue,
|
|
45
45
|
const jsi::Value* args,
|
|
46
46
|
size_t count);
|
|
47
|
-
jsi::Value
|
|
47
|
+
jsi::Value takeCommittedInstanceHandles(jsi::Runtime& rt,
|
|
48
48
|
const jsi::Value& thisValue,
|
|
49
49
|
const jsi::Value* args,
|
|
50
50
|
size_t count);
|
|
@@ -64,7 +64,7 @@ struct HybridShadowRegistry: public HybridUnistylesShadowRegistrySpec {
|
|
|
64
64
|
prototype.registerRawHybridMethod("setScopedTheme", 1, &HybridShadowRegistry::setScopedTheme);
|
|
65
65
|
prototype.registerRawHybridMethod("getScopedTheme", 0, &HybridShadowRegistry::getScopedTheme);
|
|
66
66
|
prototype.registerRawHybridMethod("verify", 0, &HybridShadowRegistry::verify);
|
|
67
|
-
prototype.registerRawHybridMethod("
|
|
67
|
+
prototype.registerRawHybridMethod("takeCommittedInstanceHandles", 0, &HybridShadowRegistry::takeCommittedInstanceHandles);
|
|
68
68
|
prototype.registerRawHybridMethod("refreshReactNodes", 1, &HybridShadowRegistry::refreshReactNodes);
|
|
69
69
|
});
|
|
70
70
|
};
|
|
@@ -73,6 +73,7 @@ struct HybridShadowRegistry: public HybridUnistylesShadowRegistrySpec {
|
|
|
73
73
|
|
|
74
74
|
private:
|
|
75
75
|
void scheduleShadowTreeUpdate(jsi::Runtime& rt);
|
|
76
|
+
static std::optional<jsi::Object> getUnistyleSecrets(jsi::Runtime& rt, jsi::Object& style, const core::Unistyle::Shared& unistyle);
|
|
76
77
|
|
|
77
78
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
|
78
79
|
std::shared_ptr<std::atomic<bool>> _isShadowTreeUpdateScheduled = std::make_shared<std::atomic<bool>>(false);
|
|
@@ -362,14 +362,14 @@ void HybridStyleSheet::applyDependencyChanges(jsi::Runtime& rt, std::vector<Unis
|
|
|
362
362
|
parser.rebuildShadowLeafUpdates(rt, dependencyMap);
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
std::vector<
|
|
365
|
+
std::vector<InstanceHandle::Shared> committedInstanceHandles;
|
|
366
366
|
|
|
367
367
|
if (!dependencyMap.empty()) {
|
|
368
|
-
|
|
368
|
+
committedInstanceHandles = shadow::ShadowTreeManager::updateShadowTree(rt);
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
// after the commit, so listeners can point React at the committed nodes
|
|
372
|
-
registry.
|
|
372
|
+
registry.setCommittedInstanceHandles(std::move(committedInstanceHandles));
|
|
373
373
|
// also when no StyleSheet depends on the change, hooks (useUnistyles, withUnistyles, Display, Hide) may
|
|
374
374
|
this->notifyJSListeners(dependencies);
|
|
375
375
|
}
|