react-native-unistyles 3.0.0-beta.3 → 3.0.0-beta.5
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 -3
- package/android/src/main/cxx/NativeUnistylesModule.cpp +1 -1
- package/android/src/main/cxx/NativeUnistylesModule.h +1 -1
- package/components/native/ActivityIndicator/package.json +2 -1
- package/components/native/FlatList/package.json +2 -1
- package/components/native/Image/package.json +2 -1
- package/components/native/ImageBackground/package.json +2 -1
- package/components/native/KeyboardAvoidingView/package.json +2 -1
- package/components/native/Pressable/package.json +1 -1
- package/components/native/RefreshControl/package.json +2 -1
- package/components/native/ScrollView/package.json +2 -1
- package/components/native/SectionList/package.json +2 -1
- package/components/native/Switch/package.json +2 -1
- package/components/native/Text/package.json +2 -1
- package/components/native/TextInput/package.json +2 -1
- package/components/native/TouchableHighlight/package.json +2 -1
- package/components/native/TouchableOpacity/package.json +2 -1
- package/components/native/View/package.json +2 -1
- package/components/native/VirtualizedList/package.json +2 -1
- package/cxx/common/Constants.h +4 -4
- package/cxx/common/Helpers.h +1 -1
- package/cxx/core/HashGenerator.cpp +23 -0
- package/cxx/core/HashGenerator.h +13 -0
- package/cxx/core/HostUnistyle.cpp +83 -0
- package/cxx/core/HostUnistyle.h +27 -0
- package/cxx/core/RNStyle.h +18 -0
- package/cxx/core/Unistyle.h +9 -4
- package/cxx/core/UnistyleWrapper.h +92 -47
- package/cxx/core/UnistylesRegistry.cpp +19 -11
- package/cxx/core/UnistylesRegistry.h +2 -4
- package/cxx/hybridObjects/HybridNavigationBar.cpp +3 -3
- package/cxx/hybridObjects/HybridNavigationBar.h +2 -2
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +32 -45
- package/cxx/hybridObjects/HybridShadowRegistry.h +0 -10
- package/cxx/hybridObjects/HybridStatusBar.cpp +3 -3
- package/cxx/hybridObjects/HybridStatusBar.h +2 -2
- package/cxx/hybridObjects/HybridStyleSheet.cpp +25 -8
- package/cxx/hybridObjects/HybridStyleSheet.h +2 -1
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +15 -15
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -2
- package/cxx/parser/Parser.cpp +17 -24
- package/cxx/parser/Parser.h +2 -1
- package/ios/NativePlatform+ios.swift +5 -7
- package/ios/NativePlatform.swift +2 -2
- package/ios/UnistylesModuleOnLoad.mm +2 -1
- package/lib/commonjs/components/ScopedTheme.js.map +1 -1
- package/lib/commonjs/components/index.js +0 -7
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/native/ImageBackground.js +45 -1
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/ImageBackground.native.js +10 -0
- package/lib/commonjs/components/native/ImageBackground.native.js.map +1 -0
- package/lib/commonjs/components/native/Pressable.js +26 -51
- package/lib/commonjs/components/native/Pressable.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +14 -11
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +29 -5
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +40 -0
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -0
- package/lib/commonjs/core/createUnistylesImageBackground.js +36 -14
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/getClassname.js +25 -0
- package/lib/commonjs/core/getClassname.js.map +1 -0
- package/lib/commonjs/core/getClassname.native.js +9 -0
- package/lib/commonjs/core/getClassname.native.js.map +1 -0
- package/lib/commonjs/core/index.js +14 -7
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/passForwardRef.js +2 -2
- package/lib/commonjs/core/passForwardRef.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/index.js +13 -0
- package/lib/commonjs/core/useProxifiedUnistyles/index.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js +22 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +26 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/types.js +6 -0
- package/lib/commonjs/core/useProxifiedUnistyles/types.js.map +1 -0
- package/lib/commonjs/core/{withUnistyles/useDependencies.js → useProxifiedUnistyles/useProxifiedUnistyles.js} +22 -22
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -0
- package/lib/commonjs/core/useUnistyles.js +19 -0
- package/lib/commonjs/core/useUnistyles.js.map +1 -0
- package/lib/commonjs/core/warn.js +16 -0
- package/lib/commonjs/core/warn.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +19 -55
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +32 -65
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/index.js +23 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/server/getServerUnistyles.js +38 -0
- package/lib/commonjs/server/getServerUnistyles.js.map +1 -0
- package/lib/commonjs/server/hydrateServerUnistyles.js +17 -0
- package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -0
- package/lib/commonjs/server/index.js +34 -0
- package/lib/commonjs/server/index.js.map +1 -0
- package/lib/commonjs/server/resetServerUnistyles.js +16 -0
- package/lib/commonjs/server/resetServerUnistyles.js.map +1 -0
- package/lib/commonjs/server/types.js +8 -0
- package/lib/commonjs/server/types.js.map +1 -0
- package/lib/commonjs/server/useServerUnistyles.js +27 -0
- package/lib/commonjs/server/useServerUnistyles.js.map +1 -0
- package/lib/commonjs/specs/ShadowRegistry/index.js +6 -3
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/utils.js +4 -2
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/object/filter.js +2 -2
- package/lib/commonjs/web/convert/object/filter.js.map +1 -1
- package/lib/commonjs/web/convert/style.js +4 -4
- package/lib/commonjs/web/convert/style.js.map +1 -1
- package/lib/commonjs/web/create.js +20 -15
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/css/core.js +55 -0
- package/lib/commonjs/web/css/core.js.map +1 -0
- package/lib/commonjs/web/css/index.js +17 -0
- package/lib/commonjs/web/css/index.js.map +1 -0
- package/lib/commonjs/web/css/state.js +155 -0
- package/lib/commonjs/web/css/state.js.map +1 -0
- package/lib/commonjs/web/css/utils.js +47 -0
- package/lib/commonjs/web/css/utils.js.map +1 -0
- package/lib/commonjs/web/index.js +14 -18
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/listener.js +9 -7
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/registry.js +44 -123
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js +28 -21
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/services.js +28 -0
- package/lib/commonjs/web/services.js.map +1 -0
- package/lib/commonjs/web/shadowRegistry.js +46 -93
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +39 -9
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/types.js +6 -0
- package/lib/commonjs/web/types.js.map +1 -0
- package/lib/commonjs/web/utils/common.js +29 -9
- package/lib/commonjs/web/utils/common.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +28 -19
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/commonjs/web/variants.js +25 -27
- package/lib/commonjs/web/variants.js.map +1 -1
- package/lib/module/components/ScopedTheme.js.map +1 -1
- package/lib/module/components/index.js +0 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/native/ImageBackground.js +45 -2
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/components/native/ImageBackground.native.js +6 -0
- package/lib/module/components/native/ImageBackground.native.js.map +1 -0
- package/lib/module/components/native/Pressable.js +27 -52
- package/lib/module/components/native/Pressable.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +15 -12
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +29 -5
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +33 -0
- package/lib/module/core/createUnistylesElement.native.js.map +1 -0
- package/lib/module/core/createUnistylesImageBackground.js +34 -13
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/getClassname.js +20 -0
- package/lib/module/core/getClassname.js.map +1 -0
- package/lib/module/core/getClassname.native.js +4 -0
- package/lib/module/core/getClassname.native.js.map +1 -0
- package/lib/module/core/index.js +2 -1
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/passForwardRef.js +2 -2
- package/lib/module/core/passForwardRef.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/index.js +4 -0
- package/lib/module/core/useProxifiedUnistyles/index.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/listener.js +17 -0
- package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/listener.native.js +21 -0
- package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/types.js +4 -0
- package/lib/module/core/useProxifiedUnistyles/types.js.map +1 -0
- package/lib/module/core/{withUnistyles/useDependencies.js → useProxifiedUnistyles/useProxifiedUnistyles.js} +19 -19
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -0
- package/lib/module/core/useUnistyles.js +14 -0
- package/lib/module/core/useUnistyles.js.map +1 -0
- package/lib/module/core/warn.js +11 -0
- package/lib/module/core/warn.js.map +1 -0
- package/lib/module/core/withUnistyles/withUnistyles.js +19 -55
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +33 -66
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/server/getServerUnistyles.js +32 -0
- package/lib/module/server/getServerUnistyles.js.map +1 -0
- package/lib/module/server/hydrateServerUnistyles.js +12 -0
- package/lib/module/server/hydrateServerUnistyles.js.map +1 -0
- package/lib/module/server/index.js +7 -0
- package/lib/module/server/index.js.map +1 -0
- package/lib/module/server/resetServerUnistyles.js +11 -0
- package/lib/module/server/resetServerUnistyles.js.map +1 -0
- package/lib/module/server/types.js +4 -0
- package/lib/module/server/types.js.map +1 -0
- package/lib/module/server/useServerUnistyles.js +22 -0
- package/lib/module/server/useServerUnistyles.js.map +1 -0
- package/lib/module/specs/ShadowRegistry/index.js +6 -3
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/utils.js +2 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/object/filter.js +2 -2
- package/lib/module/web/convert/object/filter.js.map +1 -1
- package/lib/module/web/convert/style.js +4 -4
- package/lib/module/web/convert/style.js.map +1 -1
- package/lib/module/web/create.js +20 -15
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/css/core.js +50 -0
- package/lib/module/web/css/core.js.map +1 -0
- package/lib/module/web/css/index.js +4 -0
- package/lib/module/web/css/index.js.map +1 -0
- package/lib/module/web/css/state.js +150 -0
- package/lib/module/web/css/state.js.map +1 -0
- package/lib/module/web/css/utils.js +41 -0
- package/lib/module/web/css/utils.js.map +1 -0
- package/lib/module/web/index.js +10 -5
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/listener.js +8 -7
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/registry.js +44 -124
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/runtime.js +27 -21
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/services.js +23 -0
- package/lib/module/web/services.js.map +1 -0
- package/lib/module/web/shadowRegistry.js +46 -94
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +39 -10
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/types.js +4 -0
- package/lib/module/web/types.js.map +1 -0
- package/lib/module/web/utils/common.js +26 -7
- package/lib/module/web/utils/common.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +27 -17
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web/variants.js +25 -27
- package/lib/module/web/variants.js.map +1 -1
- package/lib/typescript/src/components/index.d.ts +0 -1
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts +3 -1
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -1
- package/lib/typescript/src/components/native/FlatList.d.ts +3 -1
- package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Image.d.ts +3 -1
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ImageBackground.d.ts +8 -2
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ImageBackground.native.d.ts +3 -0
- package/lib/typescript/src/components/native/ImageBackground.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +3 -1
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.d.ts +3 -2
- package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/components/native/RefreshControl.d.ts +3 -1
- package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ScrollView.d.ts +3 -1
- package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -1
- package/lib/typescript/src/components/native/SectionList.d.ts +3 -1
- package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Switch.d.ts +3 -1
- package/lib/typescript/src/components/native/Switch.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Text.d.ts +3 -1
- package/lib/typescript/src/components/native/Text.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TextInput.d.ts +3 -1
- package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts +3 -1
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts +3 -1
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -1
- package/lib/typescript/src/components/native/View.d.ts +3 -1
- package/lib/typescript/src/components/native/View.d.ts.map +1 -1
- package/lib/typescript/src/components/native/VirtualizedList.d.ts +3 -1
- package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts +6 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts +3 -0
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/getClassname.d.ts +7 -0
- package/lib/typescript/src/core/getClassname.d.ts.map +1 -0
- package/lib/typescript/src/core/getClassname.native.d.ts +2 -0
- package/lib/typescript/src/core/getClassname.native.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -1
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/index.d.ts +2 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/index.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts +3 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts +3 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +7 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +8 -0
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/useUnistyles.d.ts +6 -0
- package/lib/typescript/src/core/useUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/warn.d.ts +3 -0
- package/lib/typescript/src/core/warn.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +0 -3
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/server/getServerUnistyles.d.ts +4 -0
- package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +8 -0
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/server/index.d.ts +5 -0
- package/lib/typescript/src/server/index.d.ts.map +1 -0
- package/lib/typescript/src/server/resetServerUnistyles.d.ts +2 -0
- package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/server/types.d.ts +5 -0
- package/lib/typescript/src/server/types.d.ts.map +1 -0
- package/lib/typescript/src/server/useServerUnistyles.d.ts +4 -0
- package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +0 -3
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +4 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- 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/style.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/css/core.d.ts +3 -0
- package/lib/typescript/src/web/css/core.d.ts.map +1 -0
- package/lib/typescript/src/web/css/index.d.ts +2 -0
- package/lib/typescript/src/web/css/index.d.ts.map +1 -0
- package/lib/typescript/src/web/css/state.d.ts +30 -0
- package/lib/typescript/src/web/css/state.d.ts.map +1 -0
- package/lib/typescript/src/web/css/utils.d.ts +4 -0
- package/lib/typescript/src/web/css/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/index.d.ts +7 -1
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener.d.ts +4 -3
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts +11 -8
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts +6 -4
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/services.d.ts +15 -0
- package/lib/typescript/src/web/services.d.ts.map +1 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts +10 -13
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts +7 -3
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +13 -0
- package/lib/typescript/src/web/types.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/common.d.ts +2 -1
- package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +5 -4
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/lib/typescript/src/web/variants.d.ts +2 -2
- package/lib/typescript/src/web/variants.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JColorScheme.hpp +2 -1
- package/nitrogen/generated/android/c++/JDimensions.hpp +2 -1
- package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +36 -10
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +53 -19
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +5 -5
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JInsets.hpp +2 -1
- package/nitrogen/generated/android/c++/JOrientation.hpp +2 -1
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +2 -1
- package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/ColorScheme.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Dimensions.kt +10 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +43 -14
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +43 -14
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +10 -10
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +13 -8
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Orientation.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +19 -14
- package/nitrogen/generated/android/unistyles+autolinking.cmake +4 -1
- package/nitrogen/generated/android/unistyles+autolinking.gradle +1 -1
- package/nitrogen/generated/android/unistylesOnLoad.cpp +7 -3
- package/nitrogen/generated/android/unistylesOnLoad.hpp +1 -1
- package/nitrogen/generated/ios/Unistyles+autolinking.rb +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +21 -6
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +105 -27
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +5 -3
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +92 -33
- package/nitrogen/generated/ios/swift/ColorScheme.swift +1 -1
- package/nitrogen/generated/ios/swift/Dimensions.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_UnistylesNativeMiniRuntime.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +36 -23
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +327 -0
- package/nitrogen/generated/ios/swift/Insets.swift +1 -1
- package/nitrogen/generated/ios/swift/Orientation.swift +1 -1
- package/nitrogen/generated/ios/swift/UnistyleDependency.swift +1 -1
- package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +1 -1
- package/nitrogen/generated/shared/c++/ColorScheme.hpp +1 -1
- package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/Insets.hpp +1 -1
- package/nitrogen/generated/shared/c++/Orientation.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -2
- package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -1
- package/package.json +21 -12
- package/plugin/import.js +1 -21
- package/plugin/index.d.ts +41 -0
- package/plugin/index.js +44 -76
- package/plugin/stylesheet.js +17 -1
- package/plugin/variants.js +49 -75
- package/src/components/ScopedTheme.tsx +1 -1
- package/src/components/index.ts +0 -1
- package/src/components/native/ImageBackground.native.tsx +4 -0
- package/src/components/native/ImageBackground.tsx +54 -2
- package/src/components/native/Pressable.native.tsx +16 -17
- package/src/components/native/Pressable.tsx +35 -69
- package/src/core/createUnistylesElement.native.tsx +36 -0
- package/src/core/createUnistylesElement.tsx +42 -8
- package/src/core/createUnistylesImageBackground.tsx +40 -19
- package/src/core/getClassname.native.ts +1 -0
- package/src/core/getClassname.ts +13 -0
- package/src/core/index.ts +2 -1
- package/src/core/passForwardRef.ts +1 -2
- package/src/core/useProxifiedUnistyles/index.ts +1 -0
- package/src/core/useProxifiedUnistyles/listener.native.ts +18 -0
- package/src/core/useProxifiedUnistyles/listener.ts +13 -0
- package/src/core/useProxifiedUnistyles/types.ts +7 -0
- package/src/core/{withUnistyles/useDependencies.ts → useProxifiedUnistyles/useProxifiedUnistyles.ts} +19 -26
- package/src/core/useUnistyles.ts +11 -0
- package/src/core/warn.ts +13 -0
- package/src/core/withUnistyles/withUnistyles.native.tsx +39 -68
- package/src/core/withUnistyles/withUnistyles.tsx +19 -56
- package/src/index.ts +3 -2
- package/src/server/getServerUnistyles.tsx +20 -0
- package/src/server/hydrateServerUnistyles.ts +17 -0
- package/src/server/index.ts +5 -0
- package/src/server/resetServerUnistyles.ts +9 -0
- package/src/server/types.ts +4 -0
- package/src/server/useServerUnistyles.tsx +22 -0
- package/src/specs/ShadowRegistry/index.ts +12 -9
- package/src/specs/StyleSheet/index.ts +5 -1
- package/src/utils.ts +15 -11
- package/src/web/convert/object/filter.ts +2 -2
- package/src/web/convert/style.ts +8 -7
- package/src/web/create.ts +23 -18
- package/src/web/css/core.ts +58 -0
- package/src/web/css/index.ts +1 -0
- package/src/web/css/state.ts +191 -0
- package/src/web/css/utils.ts +54 -0
- package/src/web/index.ts +18 -5
- package/src/web/listener.ts +8 -8
- package/src/web/registry.ts +47 -152
- package/src/web/runtime.ts +32 -22
- package/src/web/services.ts +28 -0
- package/src/web/shadowRegistry.ts +46 -104
- package/src/web/state.ts +46 -11
- package/src/web/types.ts +13 -0
- package/src/web/utils/common.ts +32 -8
- package/src/web/utils/unistyle.ts +40 -25
- package/src/web/variants.ts +27 -27
- package/cxx/core/HostStyle.cpp +0 -73
- package/cxx/core/HostStyle.h +0 -34
- package/lib/commonjs/components/Variants.js +0 -36
- package/lib/commonjs/components/Variants.js.map +0 -1
- package/lib/commonjs/core/createUnistylesComponent.js +0 -16
- package/lib/commonjs/core/createUnistylesComponent.js.map +0 -1
- package/lib/commonjs/core/withUnistyles/useDependencies.js.map +0 -1
- package/lib/module/components/Variants.js +0 -29
- package/lib/module/components/Variants.js.map +0 -1
- package/lib/module/core/createUnistylesComponent.js +0 -11
- package/lib/module/core/createUnistylesComponent.js.map +0 -1
- package/lib/module/core/withUnistyles/useDependencies.js.map +0 -1
- package/lib/typescript/src/components/Variants.d.ts +0 -7
- package/lib/typescript/src/components/Variants.d.ts.map +0 -1
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +0 -14
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +0 -1
- package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts +0 -13
- package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts.map +0 -1
- package/nitrogen/generated/android/unistylesOnLoad.kt +0 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +0 -314
- package/plugin/style.js +0 -168
- package/src/components/Variants.tsx +0 -30
- package/src/core/createUnistylesComponent.tsx +0 -14
package/plugin/import.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/** @param {import('./index').UnistylesPluginPass} state */
|
1
2
|
function addUnistylesImport(t, path, state) {
|
2
3
|
const localNames = Object.keys(state.reactNativeImports)
|
3
4
|
const names = Object.values(state.reactNativeImports)
|
@@ -38,27 +39,6 @@ function addUnistylesImport(t, path, state) {
|
|
38
39
|
path.node.body.unshift(newImport)
|
39
40
|
})
|
40
41
|
|
41
|
-
// import variants
|
42
|
-
if (state.file.hasVariants) {
|
43
|
-
const unistylesImport = path.node.body
|
44
|
-
.find(node => t.isImportDeclaration(node) && node.source.value === 'react-native-unistyles')
|
45
|
-
|
46
|
-
if (unistylesImport) {
|
47
|
-
// prevent duplications
|
48
|
-
if (!unistylesImport.specifiers.some(specifier => specifier.local.name === 'Variants')) {
|
49
|
-
unistylesImport.specifiers.push(t.importSpecifier(t.identifier('Variants'), t.identifier('Variants')))
|
50
|
-
}
|
51
|
-
} else {
|
52
|
-
// Add a new import declaration for "Variants" from "react-native-unistyles"
|
53
|
-
const newImport = t.importDeclaration(
|
54
|
-
[t.importSpecifier(t.identifier('Variants'), t.identifier('Variants'))],
|
55
|
-
t.stringLiteral('react-native-unistyles')
|
56
|
-
)
|
57
|
-
|
58
|
-
path.node.body.unshift(newImport)
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
42
|
// cleanup
|
63
43
|
nodesToRemove.forEach(node => path.node.body.splice(path.node.body.indexOf(node), 1))
|
64
44
|
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
export interface UnistylesPluginOptions {
|
2
|
+
/**
|
3
|
+
* By default babel plugin will look for any `react-native-unistyles` import to start processing your file.
|
4
|
+
* However, in some cases you might want to process files that miss such import:
|
5
|
+
* - ui-kits that aggregates Unistyles components
|
6
|
+
* - monorepos that use Unistyles under absolute path like `@codemask/styles`
|
7
|
+
*
|
8
|
+
* If that's your case, you can configure the Babel plugin to process them.
|
9
|
+
*/
|
10
|
+
autoProcessImports?: string[]
|
11
|
+
|
12
|
+
/**
|
13
|
+
* By default babel plugin will ignore `node_modules`.
|
14
|
+
* However similar to `autoProcessImports`, you can configure it to process extra paths.
|
15
|
+
*
|
16
|
+
* Under these paths we will replace `react-native` imports with `react-native-unistyles` factories that will borrow components refs [read more](https://www.unistyl.es/v3/other/babel-plugin#3-component-factory-borrowing-ref).
|
17
|
+
*
|
18
|
+
* Defaults to:
|
19
|
+
*
|
20
|
+
* ```ts
|
21
|
+
* ['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
|
22
|
+
* ```
|
23
|
+
*/
|
24
|
+
autoProcessPaths?: string[];
|
25
|
+
|
26
|
+
/**
|
27
|
+
* In order to list detected dependencies by the Babel plugin you can enable the `debug` flag.
|
28
|
+
* It will `console.log` name of the file and component with Unistyles dependencies.
|
29
|
+
*/
|
30
|
+
debug?: boolean;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Only applicable for Unistyles monorepo for
|
34
|
+
* path resolution, don't use it!
|
35
|
+
*/
|
36
|
+
isLocal?: boolean;
|
37
|
+
}
|
38
|
+
|
39
|
+
export interface UnistylesPluginPass {
|
40
|
+
opts: UnistylesPluginOptions;
|
41
|
+
}
|
package/plugin/index.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
const { addUnistylesImport, isInsideNodeModules } = require('./import')
|
2
|
-
const { getStyleMetadata, getStyleAttribute, styleAttributeToArray, handlePressable } = require('./style')
|
3
2
|
const { hasStringRef } = require('./ref')
|
4
|
-
const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyles } = require('./stylesheet')
|
5
|
-
const {
|
3
|
+
const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyles, isKindOfStyleSheet } = require('./stylesheet')
|
4
|
+
const { extractVariants } = require('./variants')
|
6
5
|
|
7
6
|
const reactNativeComponentNames = [
|
8
7
|
'ActivityIndicator',
|
@@ -20,38 +19,52 @@ const reactNativeComponentNames = [
|
|
20
19
|
'RefreshControl',
|
21
20
|
'TouchableHighlight',
|
22
21
|
'TouchableOpacity',
|
23
|
-
'VirtualizedList'
|
22
|
+
'VirtualizedList',
|
23
|
+
// Modal - there is no exposed native handle
|
24
|
+
// TouchableWithoutFeedback - can't accept a ref
|
24
25
|
]
|
25
26
|
|
26
|
-
//
|
27
|
-
//
|
27
|
+
// auto replace RN imports to Unistyles imports under these paths
|
28
|
+
// our implementation simply borrows 'ref' to register it in ShadowRegistry
|
29
|
+
// so we won't affect anyone's implementation
|
30
|
+
const REPLACE_WITH_UNISTYLES_PATHS = [
|
31
|
+
'react-native-reanimated/src/component',
|
32
|
+
'react-native-gesture-handler/src/components'
|
33
|
+
]
|
28
34
|
|
29
35
|
module.exports = function ({ types: t }) {
|
30
36
|
return {
|
31
37
|
name: 'babel-react-native-unistyles',
|
32
38
|
visitor: {
|
33
39
|
Program: {
|
40
|
+
/** @param {import('./index').UnistylesPluginPass} state */
|
34
41
|
enter(path, state) {
|
35
|
-
|
36
|
-
|
37
|
-
|
42
|
+
state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS
|
43
|
+
.concat(state.opts.autoProcessPaths ?? [])
|
44
|
+
.some(path => state.filename.includes(path))
|
38
45
|
|
39
46
|
state.file.hasAnyUnistyle = false
|
40
|
-
state.file.hasUnistylesImport = false
|
41
|
-
state.file.shouldIncludePressable = false
|
42
47
|
state.file.hasVariants = false
|
43
48
|
state.file.styleSheetLocalName = ''
|
44
49
|
state.file.tagNumber = 0
|
45
|
-
state.file.isClassComponent = false
|
46
50
|
state.reactNativeImports = {}
|
51
|
+
state.file.forceProcessing = false
|
47
52
|
},
|
48
53
|
exit(path, state) {
|
49
|
-
if (state
|
54
|
+
if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
|
55
|
+
return
|
56
|
+
}
|
57
|
+
|
58
|
+
if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles) {
|
50
59
|
addUnistylesImport(t, path, state)
|
51
60
|
}
|
52
61
|
}
|
53
62
|
},
|
54
63
|
FunctionDeclaration(path, state) {
|
64
|
+
if (isInsideNodeModules(state)) {
|
65
|
+
return
|
66
|
+
}
|
67
|
+
|
55
68
|
const componentName = path.node.id
|
56
69
|
? path.node.id.name
|
57
70
|
: null
|
@@ -61,13 +74,16 @@ module.exports = function ({ types: t }) {
|
|
61
74
|
}
|
62
75
|
},
|
63
76
|
ClassDeclaration(path, state) {
|
77
|
+
if (isInsideNodeModules(state)) {
|
78
|
+
return
|
79
|
+
}
|
80
|
+
|
64
81
|
const componentName = path.node.id
|
65
82
|
? path.node.id.name
|
66
83
|
: null
|
67
84
|
|
68
85
|
if (componentName) {
|
69
86
|
state.file.hasVariants = false
|
70
|
-
state.file.isClassComponent = true
|
71
87
|
}
|
72
88
|
},
|
73
89
|
VariableDeclaration(path, state) {
|
@@ -87,16 +103,15 @@ module.exports = function ({ types: t }) {
|
|
87
103
|
}
|
88
104
|
})
|
89
105
|
},
|
106
|
+
/** @param {import('./index').UnistylesPluginPass} state */
|
90
107
|
ImportDeclaration(path, state) {
|
91
|
-
if (isInsideNodeModules(state)) {
|
108
|
+
if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
|
92
109
|
return
|
93
110
|
}
|
94
111
|
|
95
112
|
const importSource = path.node.source.value
|
96
113
|
|
97
114
|
if (importSource.includes('react-native-unistyles')) {
|
98
|
-
state.file.hasUnistylesImport = true
|
99
|
-
|
100
115
|
path.node.specifiers.forEach(specifier => {
|
101
116
|
if (specifier.imported && specifier.imported.name === 'StyleSheet') {
|
102
117
|
state.file.styleSheetLocalName = specifier.local.name
|
@@ -104,20 +119,16 @@ module.exports = function ({ types: t }) {
|
|
104
119
|
})
|
105
120
|
}
|
106
121
|
|
107
|
-
if (importSource
|
122
|
+
if (importSource === 'react-native') {
|
108
123
|
path.node.specifiers.forEach(specifier => {
|
109
|
-
if (specifier.imported && specifier.imported.name === 'Pressable' && specifier.local.name !== 'NativePressableReactNative') {
|
110
|
-
state.file.shouldIncludePressable = true
|
111
|
-
}
|
112
|
-
|
113
124
|
if (specifier.imported && reactNativeComponentNames.includes(specifier.imported.name)) {
|
114
125
|
state.reactNativeImports[specifier.local.name] = specifier.imported.name
|
115
126
|
}
|
116
127
|
})
|
117
128
|
}
|
118
129
|
|
119
|
-
if (
|
120
|
-
state.file.
|
130
|
+
if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
|
131
|
+
state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource)
|
121
132
|
}
|
122
133
|
},
|
123
134
|
JSXElement(path, state) {
|
@@ -125,63 +136,28 @@ module.exports = function ({ types: t }) {
|
|
125
136
|
return
|
126
137
|
}
|
127
138
|
|
128
|
-
if (state.file.isClassComponent) {
|
129
|
-
return
|
130
|
-
}
|
131
|
-
|
132
|
-
const openingElement = path.node.openingElement
|
133
|
-
const openingElementName = openingElement.name.name
|
134
|
-
const isReactNativeComponent = Boolean(state.reactNativeImports[openingElementName])
|
135
|
-
const isAnimatedComponent = (
|
136
|
-
!isReactNativeComponent &&
|
137
|
-
openingElement.name.object &&
|
138
|
-
openingElement.name.object.name === 'Animated'
|
139
|
-
)
|
140
|
-
|
141
|
-
if (!isReactNativeComponent && !isAnimatedComponent) {
|
142
|
-
return
|
143
|
-
}
|
144
|
-
|
145
|
-
const styleAttr = getStyleAttribute(t, path)
|
146
|
-
|
147
|
-
// component has no style prop
|
148
|
-
if (!styleAttr) {
|
149
|
-
return
|
150
|
-
}
|
151
|
-
|
152
|
-
const metadata = getStyleMetadata(t, styleAttr.value.expression, null, state)
|
153
|
-
|
154
|
-
if (openingElementName === 'Pressable') {
|
155
|
-
return handlePressable(t, path, styleAttr, metadata, state)
|
156
|
-
}
|
157
|
-
|
158
|
-
// style prop is using unexpected expression
|
159
|
-
if (metadata.length === 0) {
|
160
|
-
return
|
161
|
-
}
|
162
|
-
|
163
|
-
styleAttributeToArray(t, path)
|
164
|
-
|
165
|
-
// to add import
|
166
|
-
state.file.hasAnyUnistyle = true
|
167
|
-
|
168
139
|
if (hasStringRef(t, path)) {
|
169
140
|
throw new Error("Detected string based ref which is not supported by Unistyles.")
|
170
141
|
}
|
171
142
|
},
|
172
|
-
|
143
|
+
BlockStatement(path, state) {
|
173
144
|
if (isInsideNodeModules(state)) {
|
174
145
|
return
|
175
146
|
}
|
176
147
|
|
177
|
-
|
178
|
-
|
148
|
+
extractVariants(t, path, state)
|
149
|
+
},
|
150
|
+
CallExpression(path, state) {
|
151
|
+
if (isInsideNodeModules(state)) {
|
152
|
+
return
|
179
153
|
}
|
180
154
|
|
181
|
-
if (!isUnistylesStyleSheet(t, path, state)) {
|
155
|
+
if (!isUnistylesStyleSheet(t, path, state) && !isKindOfStyleSheet(t, path, state)) {
|
182
156
|
return
|
183
157
|
}
|
184
158
|
|
159
|
+
state.file.hasAnyUnistyle = true
|
160
|
+
|
185
161
|
addStyleSheetTag(t, path, state)
|
186
162
|
|
187
163
|
const arg = path.node.arguments[0]
|
@@ -227,14 +203,6 @@ module.exports = function ({ types: t }) {
|
|
227
203
|
})
|
228
204
|
}
|
229
205
|
}
|
230
|
-
},
|
231
|
-
ReturnStatement(path, state) {
|
232
|
-
// ignore nested returns in JSX elements
|
233
|
-
const hasJSXParent = path.findParent(p => p.isJSXElement())
|
234
|
-
|
235
|
-
if (!hasJSXParent && state.file.hasVariants) {
|
236
|
-
addJSXVariants(t, path, state)
|
237
|
-
}
|
238
206
|
}
|
239
207
|
}
|
240
208
|
}
|
package/plugin/stylesheet.js
CHANGED
@@ -42,6 +42,20 @@ function isUnistylesStyleSheet(t, path, state) {
|
|
42
42
|
)
|
43
43
|
}
|
44
44
|
|
45
|
+
function isKindOfStyleSheet(t, path, state) {
|
46
|
+
if (!state.file.forceProcessing) {
|
47
|
+
return false
|
48
|
+
}
|
49
|
+
|
50
|
+
const callee = path.get('callee')
|
51
|
+
|
52
|
+
return (
|
53
|
+
t.isMemberExpression(callee.node) &&
|
54
|
+
callee.node.property.name === 'create' &&
|
55
|
+
t.isIdentifier(callee.node.object)
|
56
|
+
)
|
57
|
+
}
|
58
|
+
|
45
59
|
function addStyleSheetTag(t, path, state) {
|
46
60
|
const callee = path.get('callee')
|
47
61
|
const uniqueId = stringToUniqueId(state.filename.replace(state.cwd, '')) + ++state.file.tagNumber
|
@@ -49,6 +63,7 @@ function addStyleSheetTag(t, path, state) {
|
|
49
63
|
callee.container.arguments.push(t.numericLiteral(uniqueId))
|
50
64
|
}
|
51
65
|
|
66
|
+
/** @param {import('./index').UnistylesPluginPass} state */
|
52
67
|
function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
|
53
68
|
const debugMessage = deps => {
|
54
69
|
if (state.opts.debug) {
|
@@ -208,5 +223,6 @@ module.exports = {
|
|
208
223
|
isUnistylesStyleSheet,
|
209
224
|
analyzeDependencies,
|
210
225
|
addStyleSheetTag,
|
211
|
-
getUnistyles
|
226
|
+
getUnistyles,
|
227
|
+
isKindOfStyleSheet
|
212
228
|
}
|
package/plugin/variants.js
CHANGED
@@ -1,92 +1,66 @@
|
|
1
|
-
function isUsingVariants(t, path) {
|
2
|
-
const callee = path.get('callee')
|
3
|
-
|
4
|
-
return (
|
5
|
-
t.isMemberExpression(callee) &&
|
6
|
-
t.isIdentifier(callee.node.object, { name: 'styles' }) &&
|
7
|
-
t.isIdentifier(callee.node.property, { name: 'useVariants' }) &&
|
8
|
-
t.isObjectExpression(path.node.arguments[0])
|
9
|
-
)
|
10
|
-
}
|
11
|
-
|
12
1
|
function extractVariants(t, path, state) {
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
t.
|
17
|
-
|
18
|
-
arg
|
19
|
-
)
|
20
|
-
])
|
21
|
-
|
22
|
-
// Replace useVariants argument with __uni__variants
|
23
|
-
path.node.arguments[0] = t.identifier('__uni__variants')
|
24
|
-
|
25
|
-
path.insertBefore(variantDeclaration)
|
26
|
-
|
27
|
-
state.file.hasVariants = true
|
28
|
-
}
|
29
|
-
|
30
|
-
function wrapVariants(t, path) {
|
31
|
-
const wrapperElement = t.jsxElement(
|
32
|
-
t.jsxOpeningElement(
|
33
|
-
t.jsxIdentifier('Variants'),
|
34
|
-
[
|
35
|
-
t.jsxAttribute(
|
36
|
-
t.jsxIdentifier('variants'),
|
37
|
-
t.jsxExpressionContainer(t.identifier('__uni__variants'))
|
38
|
-
),
|
39
|
-
],
|
40
|
-
false
|
41
|
-
),
|
42
|
-
t.jsxClosingElement(t.jsxIdentifier('Variants')),
|
43
|
-
[]
|
44
|
-
)
|
45
|
-
|
46
|
-
const element = path.openingElement && path.openingElement.name
|
47
|
-
const isWrappedInRegularFragment = t.isJSXFragment(path)
|
48
|
-
const isWrappedInFragment = (t.isJSXMemberExpression(element) && element.object.name === 'React' && element.property.name === 'Fragment') || (t.isJSXIdentifier(element) && element.name === 'Fragment')
|
49
|
-
|
50
|
-
wrapperElement.children = (isWrappedInRegularFragment || isWrappedInFragment)
|
51
|
-
? path.children
|
52
|
-
: [path]
|
2
|
+
const maybeVariants = path.node.body.filter(node => (
|
3
|
+
t.isExpressionStatement(node) &&
|
4
|
+
t.isCallExpression(node.expression) &&
|
5
|
+
t.isMemberExpression(node.expression.callee)
|
6
|
+
))
|
53
7
|
|
54
|
-
|
55
|
-
|
56
|
-
wrapperElement.openingElement.attributes.push(...path.openingElement.attributes)
|
8
|
+
if (maybeVariants.length === 0) {
|
9
|
+
return
|
57
10
|
}
|
58
11
|
|
59
|
-
|
60
|
-
|
12
|
+
const targetVariant = maybeVariants.find(variant => {
|
13
|
+
const calleeName = variant.expression.callee.object.name
|
14
|
+
|
15
|
+
return (
|
16
|
+
t.isIdentifier(variant.expression.callee.object, { name: calleeName }) &&
|
17
|
+
t.isIdentifier(variant.expression.callee.property, { name: 'useVariants' }) &&
|
18
|
+
t.isObjectExpression(variant.expression.arguments[0])
|
19
|
+
)
|
20
|
+
})
|
61
21
|
|
62
|
-
|
63
|
-
if (!t.isReturnStatement(path.node)) {
|
22
|
+
if (!targetVariant) {
|
64
23
|
return
|
65
24
|
}
|
66
25
|
|
67
|
-
const
|
26
|
+
const calleeName = targetVariant.expression.callee.object.name
|
27
|
+
const node = targetVariant.expression
|
28
|
+
const newUniqueName = path.scope.generateUidIdentifier(calleeName)
|
68
29
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
t.blockStatement([t.returnStatement(jsxElement.alternate)])
|
74
|
-
)
|
30
|
+
// Create shadow declaration eg. const _styles = styles
|
31
|
+
const shadowDeclaration = t.variableDeclaration('const', [
|
32
|
+
t.variableDeclarator(newUniqueName, t.identifier(calleeName))
|
33
|
+
])
|
75
34
|
|
76
|
-
|
35
|
+
// Create the new call expression eg. const styles = _styles.useVariants(...)
|
36
|
+
const newCallExpression = t.callExpression(
|
37
|
+
t.memberExpression(t.identifier(newUniqueName.name), t.identifier('useVariants')),
|
38
|
+
node.arguments
|
39
|
+
)
|
40
|
+
const finalDeclaration = t.variableDeclaration('const', [
|
41
|
+
t.variableDeclarator(t.identifier(calleeName), newCallExpression)
|
42
|
+
])
|
77
43
|
|
78
|
-
|
79
|
-
|
44
|
+
// Find the current node's index, we will move everything after to new block
|
45
|
+
const pathIndex = path.node.body
|
46
|
+
.findIndex(bodyPath => bodyPath === targetVariant)
|
47
|
+
const rest = path.node.body.slice(pathIndex + 1)
|
80
48
|
|
81
|
-
|
82
|
-
|
83
|
-
|
49
|
+
// move rest to new block (scope)
|
50
|
+
const blockStatement = t.blockStatement([
|
51
|
+
finalDeclaration,
|
52
|
+
...rest
|
53
|
+
])
|
54
|
+
|
55
|
+
path.node.body = [
|
56
|
+
...path.node.body.slice(0, pathIndex),
|
57
|
+
shadowDeclaration,
|
58
|
+
blockStatement
|
59
|
+
]
|
84
60
|
|
85
|
-
|
61
|
+
state.file.hasVariants = true
|
86
62
|
}
|
87
63
|
|
88
64
|
module.exports = {
|
89
|
-
|
90
|
-
extractVariants,
|
91
|
-
addJSXVariants
|
65
|
+
extractVariants
|
92
66
|
}
|
@@ -21,7 +21,7 @@ export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeP
|
|
21
21
|
const mappedChildren = [
|
22
22
|
<Apply key={name} name={name} />,
|
23
23
|
children,
|
24
|
-
<Apply key='dispose' name={previousScopedTheme} />
|
24
|
+
<Apply key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
|
25
25
|
]
|
26
26
|
|
27
27
|
return (
|
package/src/components/index.ts
CHANGED
@@ -1,4 +1,56 @@
|
|
1
|
+
import React from 'react'
|
1
2
|
import { ImageBackground as NativeImageBackground } from 'react-native'
|
2
|
-
import {
|
3
|
+
import { forwardRef } from 'react'
|
4
|
+
import type { UnistylesValues } from '../../types'
|
5
|
+
import { getClassName } from '../../core'
|
6
|
+
import { isServer } from '../../web/utils'
|
7
|
+
import { UnistylesShadowRegistry } from '../../web'
|
3
8
|
|
4
|
-
|
9
|
+
type Props = {
|
10
|
+
style?: UnistylesValues
|
11
|
+
imageStyle?: UnistylesValues
|
12
|
+
}
|
13
|
+
|
14
|
+
export const ImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => {
|
15
|
+
let storedRef: NativeImageBackground | null = null
|
16
|
+
let storedImageRef: NativeImageBackground | null = null
|
17
|
+
const styleClassNames = getClassName(props.style)
|
18
|
+
const imageClassNames = getClassName(props.imageStyle)
|
19
|
+
|
20
|
+
return (
|
21
|
+
// @ts-expect-error - RN types are not compatible with RNW styles
|
22
|
+
<NativeImageBackground
|
23
|
+
{...props}
|
24
|
+
style={styleClassNames}
|
25
|
+
imageStyle={imageClassNames}
|
26
|
+
ref={isServer() ? undefined : ref => {
|
27
|
+
if (!ref) {
|
28
|
+
// @ts-expect-error hidden from TS
|
29
|
+
UnistylesShadowRegistry.remove(storedRef, styleClassNames?.hash)
|
30
|
+
}
|
31
|
+
|
32
|
+
storedRef = ref
|
33
|
+
// @ts-expect-error hidden from TS
|
34
|
+
UnistylesShadowRegistry.add(ref, styleClassNames?.hash)
|
35
|
+
|
36
|
+
if (typeof forwardedRef === 'function') {
|
37
|
+
return forwardedRef(ref)
|
38
|
+
}
|
39
|
+
|
40
|
+
if (forwardedRef) {
|
41
|
+
forwardedRef.current = ref
|
42
|
+
}
|
43
|
+
}}
|
44
|
+
imageRef={isServer() ? undefined : ref => {
|
45
|
+
if (!ref) {
|
46
|
+
// @ts-expect-error hidden from TS
|
47
|
+
UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash)
|
48
|
+
}
|
49
|
+
|
50
|
+
storedImageRef = ref
|
51
|
+
// @ts-expect-error hidden from TS
|
52
|
+
UnistylesShadowRegistry.add(ref, imageClassNames?.hash)
|
53
|
+
}}
|
54
|
+
/>
|
55
|
+
)
|
56
|
+
})
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { forwardRef, useRef } from 'react'
|
1
|
+
import React, { forwardRef, useEffect, useRef } from 'react'
|
2
2
|
import { Pressable as NativePressableReactNative } from 'react-native'
|
3
3
|
import type { PressableProps as Props, View } from 'react-native'
|
4
4
|
import { UnistylesShadowRegistry } from '../../specs'
|
@@ -11,6 +11,15 @@ type PressableProps = Props & {
|
|
11
11
|
export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ...props }, forwardedRef) => {
|
12
12
|
const storedRef = useRef<View | null>()
|
13
13
|
|
14
|
+
useEffect(() => {
|
15
|
+
return () => {
|
16
|
+
if (storedRef.current) {
|
17
|
+
// @ts-expect-error - this is hidden from TS
|
18
|
+
UnistylesShadowRegistry.remove(storedRef.current)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}, [])
|
22
|
+
|
14
23
|
return (
|
15
24
|
<NativePressableReactNative
|
16
25
|
{...props}
|
@@ -18,14 +27,13 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
|
|
18
27
|
const unistyles = typeof style === 'function'
|
19
28
|
? style({ pressed: false })
|
20
29
|
: style
|
21
|
-
const styles = Array.isArray(unistyles)
|
22
|
-
? unistyles
|
23
|
-
: [unistyles]
|
24
30
|
|
25
|
-
// @ts-expect-error
|
26
|
-
UnistylesShadowRegistry.add(ref,
|
31
|
+
// @ts-expect-error web types are not compatible with RN styles
|
32
|
+
UnistylesShadowRegistry.add(ref, unistyles)
|
27
33
|
|
28
|
-
|
34
|
+
if (ref) {
|
35
|
+
storedRef.current = ref
|
36
|
+
}
|
29
37
|
|
30
38
|
return passForwardedRef(props, ref, forwardedRef)
|
31
39
|
}}
|
@@ -33,22 +41,13 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
|
|
33
41
|
const unistyles = typeof style === 'function'
|
34
42
|
? style(state)
|
35
43
|
: style
|
36
|
-
const styles = Array.isArray(unistyles)
|
37
|
-
? unistyles
|
38
|
-
: [unistyles]
|
39
44
|
|
40
45
|
if (!storedRef.current) {
|
41
46
|
return unistyles
|
42
47
|
}
|
43
48
|
|
44
|
-
if (state.pressed) {
|
45
|
-
UnistylesShadowRegistry.selectVariants(variants)
|
46
|
-
}
|
47
|
-
|
48
|
-
// @ts-expect-error - this is hidden from TS
|
49
|
-
UnistylesShadowRegistry.remove(storedRef.current)
|
50
49
|
// @ts-expect-error - this is hidden from TS
|
51
|
-
UnistylesShadowRegistry.add(storedRef.current,
|
50
|
+
UnistylesShadowRegistry.add(storedRef.current, unistyles)
|
52
51
|
|
53
52
|
return unistyles
|
54
53
|
}}
|