react-native-unistyles 3.5.3 → 3.7.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 +6 -8
- package/android/build.gradle +42 -0
- package/android/src/legacy/java/com/unistyles/NativePlatform+extraWindows.kt +16 -0
- package/android/src/main/cxx/NativeUnistylesModule.cpp +5 -11
- package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +82 -39
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +73 -0
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +2 -13
- package/android/src/rn86/java/com/unistyles/NativePlatform+extraWindows.kt +28 -0
- package/cxx/common/PerformanceTracing.h +85 -0
- package/cxx/converters/BackgroundImageConverter.cpp +198 -11
- package/cxx/converters/BackgroundImageConverter.h +1 -0
- package/cxx/converters/BackgroundLayerConverter.cpp +523 -0
- package/cxx/converters/BackgroundLayerConverter.h +14 -0
- package/cxx/converters/FontVariationSettingsConverter.cpp +104 -0
- package/cxx/converters/FontVariationSettingsConverter.h +17 -0
- package/cxx/core/HostUnistyle.cpp +6 -0
- package/cxx/core/UnistyleWrapper.h +16 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +13 -0
- package/cxx/hybridObjects/HybridStyleSheet.cpp +11 -0
- package/cxx/hybridObjects/HybridStyleSheet.h +1 -0
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +10 -30
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -2
- package/cxx/parser/Parser.cpp +92 -5
- package/cxx/shadowTree/ShadowTreeDiagnostics.cpp +74 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +3 -0
- package/ios/NativePlatform+ios.swift +22 -11
- package/ios/NativePlatformListener+ios.swift +9 -0
- package/lib/commonjs/components/NamedTheme.js +4 -4
- package/lib/commonjs/components/NamedTheme.js.map +1 -1
- package/lib/commonjs/components/ScopedThemeContext.js +3 -1
- package/lib/commonjs/components/ScopedThemeContext.js.map +1 -1
- 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 +26 -19
- 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/withUnistyles/withUnistyles.js +10 -7
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +22 -3
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/mocks.js +27 -3
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +69 -76
- 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/specs/ShadowRegistry/tracing.js +26 -0
- package/lib/commonjs/specs/ShadowRegistry/tracing.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/utils.js +52 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/index.js +19 -1
- package/lib/commonjs/web/convert/index.js.map +1 -1
- package/lib/commonjs/web/convert/module.d.ts +3 -0
- package/lib/commonjs/web/convert/object/backgroundLayers.js +30 -0
- package/lib/commonjs/web/convert/object/backgroundLayers.js.map +1 -0
- package/lib/commonjs/web/convert/object/fontVariationSettings.js +12 -0
- package/lib/commonjs/web/convert/object/fontVariationSettings.js.map +1 -0
- package/lib/commonjs/web/convert/object/index.js +22 -0
- package/lib/commonjs/web/convert/object/index.js.map +1 -1
- package/lib/commonjs/web/convert/utils.js +7 -1
- package/lib/commonjs/web/convert/utils.js.map +1 -1
- package/lib/commonjs/web/registry.js +6 -4
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js +9 -6
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +9 -3
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/module/components/NamedTheme.js +4 -4
- package/lib/module/components/NamedTheme.js.map +1 -1
- package/lib/module/components/ScopedThemeContext.js +3 -1
- package/lib/module/components/ScopedThemeContext.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 +26 -19
- 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/withUnistyles/withUnistyles.js +9 -6
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +24 -5
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/mocks.js +27 -3
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +69 -76
- 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/specs/ShadowRegistry/tracing.js +21 -0
- package/lib/module/specs/ShadowRegistry/tracing.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/utils.js +50 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/index.js +22 -3
- package/lib/module/web/convert/index.js.map +1 -1
- package/lib/module/web/convert/module.d.ts +3 -0
- package/lib/module/web/convert/object/backgroundLayers.js +25 -0
- package/lib/module/web/convert/object/backgroundLayers.js.map +1 -0
- package/lib/module/web/convert/object/fontVariationSettings.js +7 -0
- package/lib/module/web/convert/object/fontVariationSettings.js.map +1 -0
- package/lib/module/web/convert/object/index.js +2 -0
- package/lib/module/web/convert/object/index.js.map +1 -1
- package/lib/module/web/convert/utils.js +4 -0
- package/lib/module/web/convert/utils.js.map +1 -1
- package/lib/module/web/registry.js +6 -4
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/runtime.js +9 -6
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +10 -4
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/typescript/src/components/ScopedThemeContext.d.ts +2 -1
- package/lib/typescript/src/components/ScopedThemeContext.d.ts.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/withUnistyles/withUnistyles.d.ts +6 -3
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +7 -4
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- 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/tracing.d.ts +2 -0
- package/lib/typescript/src/specs/ShadowRegistry/tracing.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/utils.d.ts +1 -0
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/backgroundLayers.d.ts +4 -0
- package/lib/typescript/src/web/convert/object/backgroundLayers.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/object/fontVariationSettings.d.ts +4 -0
- package/lib/typescript/src/web/convert/object/fontVariationSettings.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/object/index.d.ts +2 -0
- package/lib/typescript/src/web/convert/object/index.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/utils.d.ts +2 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts +1 -0
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/metro/babel-transformer.js +1102 -0
- package/metro/index.d.ts +31 -0
- package/metro/index.js +170 -0
- package/package.json +50 -32
- package/plugin/index.d.ts +7 -0
- package/plugin/index.js +115 -33
- package/src/components/NamedTheme.tsx +5 -5
- package/src/components/ScopedThemeContext.ts +6 -2
- 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 +33 -25
- package/src/core/createUnistylesTouchableHighlight.tsx +5 -0
- package/src/core/getClassname.ts +10 -1
- package/src/core/hasUnistyles.ts +20 -0
- package/src/core/withUnistyles/withUnistyles.native.tsx +28 -6
- package/src/core/withUnistyles/withUnistyles.tsx +6 -6
- package/src/mocks.ts +14 -5
- package/src/specs/ShadowRegistry/index.ts +62 -103
- package/src/specs/ShadowRegistry/styleSource.ts +78 -0
- package/src/specs/ShadowRegistry/tracing.ts +23 -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/utils.ts +51 -0
- package/src/web/convert/index.ts +39 -3
- package/src/web/convert/object/backgroundLayers.ts +33 -0
- package/src/web/convert/object/fontVariationSettings.ts +7 -0
- package/src/web/convert/object/index.ts +2 -0
- package/src/web/convert/utils.ts +11 -0
- package/src/web/registry.ts +7 -8
- package/src/web/runtime.ts +7 -7
- package/src/web/utils/unistyle.ts +11 -4
- package/lib/commonjs/web/convert/module.d.js +0 -2
- package/lib/commonjs/web/convert/module.d.js.map +0 -1
- package/lib/module/web/convert/module.d.js +0 -2
- package/lib/module/web/convert/module.d.js.map +0 -1
- 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-child-selector.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/web-child-selector.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-pointer-events.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/web-pointer-events.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/lib/typescript/src/__tests__/withUnistyles.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts.map +0 -1
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// Keeps Reanimated's CSS style copy (`_cssStyle`) in sync with native-only style updates.
|
|
2
|
+
// Private fields are pinned by test/reanimated-contract.test.ts for 4.5 and 4.7.
|
|
3
|
+
import type { Host } from '../host'
|
|
4
|
+
import type { OwnerAdapter, StyleSource } from './registry'
|
|
5
|
+
import * as fiber from '../fiber'
|
|
6
|
+
|
|
7
|
+
// Bound once: Metro's inline requires
|
|
8
|
+
const { contextReaderFor } = fiber
|
|
9
|
+
const CLASS_COMPONENT = fiber.Tag.ClassComponent
|
|
10
|
+
|
|
11
|
+
type CSSManagerLike = { update(style: Record<string, unknown>, props?: Record<string, unknown>): void }
|
|
12
|
+
|
|
13
|
+
type AnimatedComponentLike = {
|
|
14
|
+
props: Record<string, any>
|
|
15
|
+
_cssStyle: Record<string, unknown>
|
|
16
|
+
_CSSManager?: CSSManagerLike
|
|
17
|
+
// true between componentWillUnmount and componentDidMount: also while frozen, suspended or in a hidden Activity
|
|
18
|
+
_willUnmount?: boolean
|
|
19
|
+
_updateStyles(props: Record<string, any>): void
|
|
20
|
+
shouldComponentUpdate(nextProps: Record<string, any>, ...rest: Array<unknown>): boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type AttachedState = {
|
|
24
|
+
source: StyleSource
|
|
25
|
+
original: (props: Record<string, any>) => void
|
|
26
|
+
originalShouldUpdate: AnimatedComponentLike['shouldComponentUpdate']
|
|
27
|
+
rendering: boolean
|
|
28
|
+
styleProp: unknown
|
|
29
|
+
epoch: number
|
|
30
|
+
contextKeys: Array<unknown>
|
|
31
|
+
fresh: Record<string, unknown> | undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Symbol.for: two copies of unifiber in one bundle never wrap a component twice
|
|
35
|
+
const STATE = Symbol.for('unifiber.reanimated.css')
|
|
36
|
+
|
|
37
|
+
// Kept out of AnimatedComponentLike: a unique symbol in a public type breaks consumers' declaration builds (TS4023)
|
|
38
|
+
type Attached = AnimatedComponentLike & { [STATE]?: AttachedState }
|
|
39
|
+
|
|
40
|
+
const hasCSSConfig = (cssStyle: Record<string, unknown>) => {
|
|
41
|
+
for (const key in cssStyle) {
|
|
42
|
+
if (key.startsWith('transition') || key.startsWith('animation')) {
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Keyframe animations and pseudo-styles register again on update after componentWillUnmount cleaned them up.
|
|
51
|
+
// React runs no componentWillUnmount for a subtree deleted while hidden, so on a hidden owner they would leak.
|
|
52
|
+
const registersOnUpdate = (cssStyle: Record<string, unknown>) => {
|
|
53
|
+
for (const key in cssStyle) {
|
|
54
|
+
if (key.startsWith('animation')) {
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const value = cssStyle[key]
|
|
59
|
+
|
|
60
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
61
|
+
for (const selector in value) {
|
|
62
|
+
if (selector === 'default' || selector.startsWith(':')) {
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
break
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Deepest case: ScrollView with refreshControl on Android, 6-7 fibers
|
|
75
|
+
const MAX_OWNER_DEPTH = 12
|
|
76
|
+
|
|
77
|
+
// The class whose `_componentRef` is this host's public instance. Lists don't match: their ref isn't a host.
|
|
78
|
+
export const animatedComponentOf = (host: Host | null | undefined): AnimatedComponentLike | null => {
|
|
79
|
+
const fiber = host as any
|
|
80
|
+
|
|
81
|
+
if (fiber?.memoizedProps?.collapsable !== false) {
|
|
82
|
+
return null
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const publicInstance = fiber.stateNode?.canonical?.publicInstance
|
|
86
|
+
|
|
87
|
+
if (!publicInstance) {
|
|
88
|
+
return null
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let current = fiber.return
|
|
92
|
+
|
|
93
|
+
for (let depth = 0; current && depth < MAX_OWNER_DEPTH; depth++) {
|
|
94
|
+
if (current.tag === CLASS_COMPONENT && current.stateNode?._componentRef === publicInstance) {
|
|
95
|
+
return isAnimatedComponent(current.stateNode) ? current.stateNode : null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
current = current.return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const isAnimatedComponent = (owner: any): owner is AnimatedComponentLike =>
|
|
105
|
+
typeof owner?._updateStyles === 'function' &&
|
|
106
|
+
typeof owner.shouldComponentUpdate === 'function' &&
|
|
107
|
+
owner._cssStyle !== null &&
|
|
108
|
+
typeof owner._cssStyle === 'object'
|
|
109
|
+
|
|
110
|
+
function updateStylesThroughSource(this: Attached, props: Record<string, any>) {
|
|
111
|
+
const state = this[STATE]!
|
|
112
|
+
|
|
113
|
+
state.original.call(this, props)
|
|
114
|
+
|
|
115
|
+
if (!hasCSSConfig(this._cssStyle)) {
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const epoch = state.source.epoch()
|
|
120
|
+
const read = contextReaderFor(this, state.rendering)
|
|
121
|
+
const contexts = state.source.contexts ?? []
|
|
122
|
+
let contextChanged = false
|
|
123
|
+
|
|
124
|
+
for (let i = 0; i < contexts.length; i++) {
|
|
125
|
+
const context = contexts[i]!
|
|
126
|
+
const value = read(context)
|
|
127
|
+
const key = state.source.contextKey ? state.source.contextKey(context, value) : value
|
|
128
|
+
|
|
129
|
+
if (state.contextKeys[i] !== key) {
|
|
130
|
+
state.contextKeys[i] = key
|
|
131
|
+
contextChanged = true
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (contextChanged || state.styleProp !== props.style || state.epoch !== epoch) {
|
|
136
|
+
state.fresh = state.source.resolve(props, read)
|
|
137
|
+
state.styleProp = props.style
|
|
138
|
+
state.epoch = epoch
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const fresh = state.fresh
|
|
142
|
+
|
|
143
|
+
if (!fresh) {
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// only the keys Reanimated kept: animated styles were split out of _cssStyle
|
|
148
|
+
for (const key in this._cssStyle) {
|
|
149
|
+
if (key in fresh) {
|
|
150
|
+
this._cssStyle[key] = fresh[key]
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Marks the render phase, where context must be read from React's stack
|
|
156
|
+
function shouldUpdateMarkingRender(this: Attached, ...args: [Record<string, any>, ...Array<unknown>]) {
|
|
157
|
+
const state = this[STATE]!
|
|
158
|
+
|
|
159
|
+
state.rendering = true
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
return state.originalShouldUpdate.apply(this, args)
|
|
163
|
+
} finally {
|
|
164
|
+
state.rendering = false
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export const reanimatedCSSAdapter: OwnerAdapter<AnimatedComponentLike> = {
|
|
169
|
+
name: 'react-native-reanimated/css',
|
|
170
|
+
gate: (host: Host) => (host as unknown as fiber.RawFiber).memoizedProps?.collapsable === false,
|
|
171
|
+
claim: animatedComponentOf,
|
|
172
|
+
attach: (owner: Attached, source) => {
|
|
173
|
+
if (owner[STATE]) {
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
owner[STATE] = {
|
|
178
|
+
source,
|
|
179
|
+
original: owner._updateStyles,
|
|
180
|
+
originalShouldUpdate: owner.shouldComponentUpdate,
|
|
181
|
+
rendering: false,
|
|
182
|
+
styleProp: undefined,
|
|
183
|
+
epoch: -1,
|
|
184
|
+
contextKeys: [],
|
|
185
|
+
fresh: undefined,
|
|
186
|
+
}
|
|
187
|
+
owner._updateStyles = updateStylesThroughSource
|
|
188
|
+
owner.shouldComponentUpdate = shouldUpdateMarkingRender
|
|
189
|
+
},
|
|
190
|
+
refresh: (owner) => {
|
|
191
|
+
// not mounted yet
|
|
192
|
+
if (typeof owner._CSSManager?.update !== 'function') {
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Hidden transitions still run, so the reveal shows the new value instead of animating from the old one
|
|
197
|
+
if (owner._willUnmount === true && registersOnUpdate(owner._cssStyle)) {
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
owner._updateStyles(owner.props)
|
|
202
|
+
owner._CSSManager.update(owner._cssStyle, owner.props)
|
|
203
|
+
},
|
|
204
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Context } from 'react'
|
|
2
|
+
import type { ContextReader } from '../fiber'
|
|
3
|
+
import type { Host } from '../host'
|
|
4
|
+
|
|
5
|
+
export interface StyleSource {
|
|
6
|
+
readonly name: string
|
|
7
|
+
// bumps on every runtime change (theme, breakpoint, ...)
|
|
8
|
+
epoch(): number
|
|
9
|
+
readonly contexts?: ReadonlyArray<Context<any>>
|
|
10
|
+
// cache key for a context value; default: the value itself. Stable scopes renamed in place need `scope?.name`
|
|
11
|
+
contextKey?(context: Context<any>, value: unknown): unknown
|
|
12
|
+
// undefined: none of these styles belong to this source
|
|
13
|
+
resolve(props: Record<string, any>, read: ContextReader): Record<string, unknown> | undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface OwnerAdapter<Owner extends object = object> {
|
|
17
|
+
readonly name: string
|
|
18
|
+
// runs on every link: keep it to a property read or two
|
|
19
|
+
gate(host: Host): boolean
|
|
20
|
+
claim(host: Host): Owner | null
|
|
21
|
+
attach(owner: Owner, source: StyleSource): void
|
|
22
|
+
// runs for hidden owners too (frozen, suspended, hidden Activity): skip there what can't run while hidden
|
|
23
|
+
refresh(owner: Owner, source: StyleSource): void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type OwnerRegistry = {
|
|
27
|
+
link(host: Host | null | undefined): void
|
|
28
|
+
refresh(hosts: ReadonlyArray<Host | null | undefined>): void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// An adapter that throws is disabled for the session and reported once
|
|
32
|
+
export const createOwnerRegistry = (
|
|
33
|
+
source: StyleSource,
|
|
34
|
+
adapters: ReadonlyArray<OwnerAdapter<any>>,
|
|
35
|
+
onAdapterError?: (reason: string) => void,
|
|
36
|
+
): OwnerRegistry => {
|
|
37
|
+
const disabledAdapters = new Set<OwnerAdapter>()
|
|
38
|
+
const disable = (adapter: OwnerAdapter, error: unknown) => {
|
|
39
|
+
disabledAdapters.add(adapter)
|
|
40
|
+
onAdapterError?.(`adapter ${adapter.name} failed: ${String(error)}`)
|
|
41
|
+
}
|
|
42
|
+
// Not inline closures: a closure in link() makes Hermes allocate its environment on every call
|
|
43
|
+
const attachOwner = (adapter: OwnerAdapter, host: Host) => {
|
|
44
|
+
try {
|
|
45
|
+
const owner = adapter.claim(host)
|
|
46
|
+
|
|
47
|
+
if (owner) {
|
|
48
|
+
adapter.attach(owner, source)
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
disable(adapter, error)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const refreshOwner = (adapter: OwnerAdapter, host: Host, seen: Set<object>) => {
|
|
55
|
+
try {
|
|
56
|
+
const owner = adapter.claim(host)
|
|
57
|
+
|
|
58
|
+
if (owner && !seen.has(owner)) {
|
|
59
|
+
seen.add(owner)
|
|
60
|
+
adapter.attach(owner, source)
|
|
61
|
+
adapter.refresh(owner, source)
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
disable(adapter, error)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
link(host) {
|
|
70
|
+
if (!host) {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (let i = 0; i < adapters.length; i++) {
|
|
75
|
+
const adapter = adapters[i]!
|
|
76
|
+
|
|
77
|
+
if (adapter.gate(host) && !disabledAdapters.has(adapter)) {
|
|
78
|
+
attachOwner(adapter, host)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
refresh(hosts) {
|
|
83
|
+
const seen = new Set<object>()
|
|
84
|
+
|
|
85
|
+
for (let h = 0; h < hosts.length; h++) {
|
|
86
|
+
const host = hosts[h]
|
|
87
|
+
|
|
88
|
+
if (!host) {
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (let i = 0; i < adapters.length; i++) {
|
|
93
|
+
const adapter = adapters[i]!
|
|
94
|
+
|
|
95
|
+
if (adapter.gate(host) && !disabledAdapters.has(adapter)) {
|
|
96
|
+
refreshOwner(adapter, host, seen)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { RawFiber } from './fiber'
|
|
2
|
+
import type { Host } from './host'
|
|
3
|
+
import * as host from './host'
|
|
4
|
+
|
|
5
|
+
// Bound once: Metro's inline requires
|
|
6
|
+
const { committedHalf, fiberOf } = host
|
|
7
|
+
|
|
8
|
+
const styleDiffers = (a: RawFiber, b: RawFiber) => a.memoizedProps?.style !== b.memoizedProps?.style
|
|
9
|
+
|
|
10
|
+
const flattenInto = (style: unknown, out: Record<string, unknown>) => {
|
|
11
|
+
if (Array.isArray(style)) {
|
|
12
|
+
for (let i = 0; i < style.length; i++) {
|
|
13
|
+
flattenInto(style[i], out)
|
|
14
|
+
}
|
|
15
|
+
} else if (style && typeof style === 'object') {
|
|
16
|
+
Object.assign(out, style)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return out
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type Drift = { key: string; react: unknown; expected: unknown }
|
|
23
|
+
|
|
24
|
+
// Keys that differ from React's committed props: React re-sends them on the view's next render
|
|
25
|
+
export const verify = (host: Host, expected: Record<string, unknown>): Array<Drift> => {
|
|
26
|
+
const baseline = committedHalf(fiberOf(host), styleDiffers) ?? fiberOf(host)
|
|
27
|
+
const react = flattenInto(baseline.memoizedProps?.style, {})
|
|
28
|
+
const drift: Array<Drift> = []
|
|
29
|
+
|
|
30
|
+
for (const key in expected) {
|
|
31
|
+
if (react[key] !== expected[key]) {
|
|
32
|
+
drift.push({ key, react: react[key], expected: expected[key] })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return drift
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Development builds only
|
|
40
|
+
export const getOwners = (host: Host, max = 8): Array<string> => {
|
|
41
|
+
const owners: Array<string> = []
|
|
42
|
+
|
|
43
|
+
for (let owner = fiberOf(host)._debugOwner; owner && owners.length < max; owner = owner._debugOwner ?? owner.owner) {
|
|
44
|
+
const name = owner.name ?? owner.type?.displayName ?? owner.type?.name ?? owner.type?.render?.name
|
|
45
|
+
|
|
46
|
+
if (name) {
|
|
47
|
+
owners.push(name)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return owners
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Development builds only
|
|
55
|
+
export const getCreationStack = (host: Host): string | undefined => fiberOf(host)._debugStack?.stack
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// The only module that reads React's fiber fields. A missing field gives undefined / null for that call, never a throw.
|
|
2
|
+
import type { Context } from 'react'
|
|
3
|
+
|
|
4
|
+
// ReactWorkTags, React 19
|
|
5
|
+
export const Tag = {
|
|
6
|
+
ClassComponent: 1,
|
|
7
|
+
HostRoot: 3,
|
|
8
|
+
HostComponent: 5,
|
|
9
|
+
ContextProvider: 10,
|
|
10
|
+
Suspense: 13,
|
|
11
|
+
Offscreen: 22,
|
|
12
|
+
Activity: 31,
|
|
13
|
+
} as const
|
|
14
|
+
|
|
15
|
+
declare const brand: unique symbol
|
|
16
|
+
export type FiberNode = { readonly [brand]: 'FiberNode' }
|
|
17
|
+
export type ShadowNode = { readonly __hostObjectShadowNodeWrapper?: unknown }
|
|
18
|
+
|
|
19
|
+
export type RawFiber = {
|
|
20
|
+
tag: number
|
|
21
|
+
type: any
|
|
22
|
+
return: RawFiber | null
|
|
23
|
+
child: RawFiber | null
|
|
24
|
+
sibling: RawFiber | null
|
|
25
|
+
alternate: RawFiber | null
|
|
26
|
+
stateNode: any
|
|
27
|
+
memoizedProps: any
|
|
28
|
+
pendingProps: any
|
|
29
|
+
memoizedState: any
|
|
30
|
+
_debugOwner?: any
|
|
31
|
+
_debugStack?: { stack?: string } | null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const raw = (fiber: FiberNode | null | undefined) => fiber as unknown as RawFiber | null | undefined
|
|
35
|
+
|
|
36
|
+
export const hostFiberOf = (instance: unknown): FiberNode | null =>
|
|
37
|
+
((instance as any)?.__internalInstanceHandle ?? null) as FiberNode | null
|
|
38
|
+
|
|
39
|
+
// RN composites that keep their host behind a ref of their own, most common first
|
|
40
|
+
const compositeHostRefs: Array<(handle: any) => unknown> = [
|
|
41
|
+
(handle) => handle?.getScrollResponder?.()?.getNativeScrollRef?.(), // FlatList, SectionList, VirtualizedList
|
|
42
|
+
(handle) => handle?.getNativeScrollRef?.(), // ScrollView
|
|
43
|
+
(handle) => handle?._viewRef, // ImageBackground
|
|
44
|
+
(handle) => handle?.viewRef?.current, // KeyboardAvoidingView
|
|
45
|
+
(handle) => handle?._nativeRef, // RefreshControl
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
export const resolveHostFiber = (handle: unknown): FiberNode | null => {
|
|
49
|
+
const direct = hostFiberOf(handle)
|
|
50
|
+
|
|
51
|
+
if (direct || !handle) {
|
|
52
|
+
return direct
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < compositeHostRefs.length; i++) {
|
|
56
|
+
const fiber = hostFiberOf(compositeHostRefs[i]!(handle))
|
|
57
|
+
|
|
58
|
+
if (fiber) {
|
|
59
|
+
return fiber
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const fiberOfInstance = (instance: unknown): FiberNode | null =>
|
|
67
|
+
((instance as any)?._reactInternals ?? null) as FiberNode | null
|
|
68
|
+
|
|
69
|
+
export const firstHostBelow = (fiber: FiberNode | null): FiberNode | null => {
|
|
70
|
+
let current = raw(fiber)
|
|
71
|
+
|
|
72
|
+
while (current && current.tag !== Tag.HostComponent) {
|
|
73
|
+
current = current.child
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return (current ?? null) as FiberNode | null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const hostAncestor = (fiber: FiberNode | null, levels = 1): FiberNode | null => {
|
|
80
|
+
let current = raw(fiber)?.return
|
|
81
|
+
|
|
82
|
+
while (current) {
|
|
83
|
+
if (current.tag === Tag.HostComponent && --levels === 0) {
|
|
84
|
+
return current as unknown as FiberNode
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
current = current.return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const shadowNodesOf = (fiber: FiberNode | null, out: Array<ShadowNode>) => {
|
|
94
|
+
const current = raw(fiber)
|
|
95
|
+
const node = current?.stateNode?.node
|
|
96
|
+
const alternateNode = current?.alternate?.stateNode?.node
|
|
97
|
+
|
|
98
|
+
if (node) {
|
|
99
|
+
out.push(node)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (alternateNode && alternateNode !== node) {
|
|
103
|
+
out.push(alternateNode)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const childOfParent = (parent: RawFiber, a: RawFiber, b: RawFiber): RawFiber | null => {
|
|
108
|
+
for (let child = parent.child; child; child = child.sibling) {
|
|
109
|
+
if (child === a || child === b) {
|
|
110
|
+
return child
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return null
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// React 19.2 findCurrentFiberUsingSlowPath, returning null where React throws
|
|
118
|
+
export const committedOf = (fiber: FiberNode | null): FiberNode | null => {
|
|
119
|
+
const self = raw(fiber)
|
|
120
|
+
|
|
121
|
+
if (!self) {
|
|
122
|
+
return null
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const alternate = self.alternate
|
|
126
|
+
|
|
127
|
+
if (!alternate) {
|
|
128
|
+
let root = self
|
|
129
|
+
|
|
130
|
+
while (root.return) {
|
|
131
|
+
root = root.return
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return root.tag === Tag.HostRoot ? fiber : null
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let a: RawFiber = self
|
|
138
|
+
let b: RawFiber = alternate
|
|
139
|
+
|
|
140
|
+
while (true) {
|
|
141
|
+
const parentA = a.return
|
|
142
|
+
|
|
143
|
+
if (!parentA) {
|
|
144
|
+
break
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const parentB = parentA.alternate
|
|
148
|
+
|
|
149
|
+
if (!parentB) {
|
|
150
|
+
const next = parentA.return
|
|
151
|
+
|
|
152
|
+
if (next) {
|
|
153
|
+
a = next
|
|
154
|
+
continue
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
break
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (parentA.child === parentB.child) {
|
|
161
|
+
const found = childOfParent(parentA, a, b)
|
|
162
|
+
|
|
163
|
+
return found === a ? fiber : found === b ? (alternate as unknown as FiberNode) : null
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (a.return !== b.return) {
|
|
167
|
+
a = parentA
|
|
168
|
+
b = parentB
|
|
169
|
+
} else {
|
|
170
|
+
const inA = childOfParent(parentA, a, b)
|
|
171
|
+
const inB = inA ? null : childOfParent(parentB, a, b)
|
|
172
|
+
|
|
173
|
+
if (!inA && !inB) {
|
|
174
|
+
return null
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const aUnderA = inA ? inA === a : inB !== a
|
|
178
|
+
|
|
179
|
+
a = aUnderA ? parentA : parentB
|
|
180
|
+
b = aUnderA ? parentB : parentA
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (a.alternate !== b) {
|
|
184
|
+
return null
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (a.tag !== Tag.HostRoot) {
|
|
189
|
+
return null
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return a.stateNode?.current === a ? fiber : (alternate as unknown as FiberNode)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// a provider's other half can hold its previous value
|
|
196
|
+
const committedProviderValue = (provider: RawFiber): unknown => {
|
|
197
|
+
const alternate = provider.alternate
|
|
198
|
+
|
|
199
|
+
if (!alternate || alternate.memoizedProps?.value === provider.memoizedProps?.value) {
|
|
200
|
+
return provider.memoizedProps?.value
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return (raw(committedOf(provider as unknown as FiberNode)) ?? provider).memoizedProps?.value
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export const readContext = <T>(fiber: FiberNode | null, context: Context<T>, fallback?: T): T | undefined => {
|
|
207
|
+
for (let current = raw(fiber)?.return; current; current = current.return) {
|
|
208
|
+
if (current.tag === Tag.ContextProvider && (current.type === context || current.type?._context === context)) {
|
|
209
|
+
return committedProviderValue(current) as T
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return fallback
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Fabric is a secondary renderer: its context stack is `_currentValue2`. Only valid during render.
|
|
217
|
+
export const readContextDuringRender = <T>(context: Context<T>): T | undefined =>
|
|
218
|
+
(context as any)?._currentValue2
|
|
219
|
+
|
|
220
|
+
export type ContextReader = <T>(context: Context<T>) => T | undefined
|
|
221
|
+
|
|
222
|
+
export const contextReaderFor = (instance: unknown, rendering: boolean): ContextReader =>
|
|
223
|
+
rendering ? readContextDuringRender : (context) => readCommittedContext(instance, context)
|
|
224
|
+
|
|
225
|
+
const NO_PROVIDER = Symbol('no provider')
|
|
226
|
+
|
|
227
|
+
const readCommittedContext = <T>(instance: unknown, context: Context<T>): T | undefined => {
|
|
228
|
+
const value = readContext(committedOf(fiberOfInstance(instance)), context, NO_PROVIDER as T)
|
|
229
|
+
|
|
230
|
+
return value === NO_PROVIDER ? readContextDuringRender(context) : value
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// pendingProps too, so React still bails out. Replaced, not mutated: props are frozen in dev.
|
|
234
|
+
export const patchRenderedProps = (
|
|
235
|
+
fiber: FiberNode | null,
|
|
236
|
+
patch: (props: Record<string, any>) => Record<string, any> | undefined,
|
|
237
|
+
): boolean => {
|
|
238
|
+
const self = raw(fiber)
|
|
239
|
+
|
|
240
|
+
if (!self) {
|
|
241
|
+
return false
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const patchedSelf = replaceProps(self, patch)
|
|
245
|
+
const patchedAlternate = self.alternate ? replaceProps(self.alternate, patch) : false
|
|
246
|
+
|
|
247
|
+
return patchedSelf || patchedAlternate
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const replaceProps = (target: RawFiber, patch: (props: Record<string, any>) => Record<string, any> | undefined) => {
|
|
251
|
+
const props = target.memoizedProps
|
|
252
|
+
const next = props ? patch(props) : undefined
|
|
253
|
+
|
|
254
|
+
if (!next) {
|
|
255
|
+
return false
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
target.memoizedProps = next
|
|
259
|
+
target.pendingProps = next
|
|
260
|
+
|
|
261
|
+
return true
|
|
262
|
+
}
|