react-native-unistyles 2.4.0-rc.2 → 2.5.0-rc.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/lib/commonjs/common.js +3 -1
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/UnistyleRegistry.js +8 -4
- package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
- package/lib/commonjs/core/Unistyles.js +7 -0
- package/lib/commonjs/core/Unistyles.js.map +1 -1
- package/lib/commonjs/core/mocks/UnistylesMockedBridge.js +32 -0
- package/lib/commonjs/core/mocks/UnistylesMockedBridge.js.map +1 -0
- package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js +46 -0
- package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js.map +1 -0
- package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js +77 -0
- package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js.map +1 -0
- package/lib/commonjs/core/mocks/index.js +27 -0
- package/lib/commonjs/core/mocks/index.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +2 -2
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
- package/lib/commonjs/useStyles.js +1 -1
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/module/common.js +2 -0
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/UnistyleRegistry.js +9 -5
- package/lib/module/core/UnistyleRegistry.js.map +1 -1
- package/lib/module/core/Unistyles.js +8 -1
- package/lib/module/core/Unistyles.js.map +1 -1
- package/lib/module/core/mocks/UnistylesMockedBridge.js +25 -0
- package/lib/module/core/mocks/UnistylesMockedBridge.js.map +1 -0
- package/lib/module/core/mocks/UnistylesMockedRegistry.js +39 -0
- package/lib/module/core/mocks/UnistylesMockedRegistry.js.map +1 -0
- package/lib/module/core/mocks/UnistylesMockedRuntime.js +69 -0
- package/lib/module/core/mocks/UnistylesMockedRuntime.js.map +1 -0
- package/lib/module/core/mocks/index.js +4 -0
- package/lib/module/core/mocks/index.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +2 -2
- package/lib/module/hooks/useUnistyles.js.map +1 -1
- package/lib/module/useStyles.js +1 -1
- package/lib/module/useStyles.js.map +1 -1
- package/lib/typescript/src/common.d.ts +2 -0
- package/lib/typescript/src/common.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
- package/lib/typescript/src/core/Unistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts +24 -0
- package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts.map +1 -0
- package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts +21 -0
- package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts.map +1 -0
- package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts +41 -0
- package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts.map +1 -0
- package/lib/typescript/src/core/mocks/index.d.ts +4 -0
- package/lib/typescript/src/core/mocks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +2 -1
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +2 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common.ts +2 -0
- package/src/core/UnistyleRegistry.ts +11 -5
- package/src/core/Unistyles.ts +10 -1
- package/src/core/mocks/UnistylesMockedBridge.ts +26 -0
- package/src/core/mocks/UnistylesMockedRegistry.ts +47 -0
- package/src/core/mocks/UnistylesMockedRuntime.ts +92 -0
- package/src/core/mocks/index.ts +3 -0
- package/src/hooks/useUnistyles.ts +2 -2
- package/src/types/breakpoints.ts +2 -1
- package/src/types/stylesheet.ts +2 -1
- package/src/useStyles.ts +1 -1
- package/windows/ReactNativeUnistyles/ReactNativeUnistyles.h +33 -27
    
        package/src/types/breakpoints.ts
    CHANGED
    
    | @@ -2,6 +2,7 @@ import type { ColorValue, OpaqueColorValue } from 'react-native' | |
| 2 2 | 
             
            import type { UnistylesTheme } from '../types'
         | 
| 3 3 | 
             
            import type { BreakpointsOrMediaQueries, ToDeepUnistyles } from './stylesheet'
         | 
| 4 4 | 
             
            import type { TransformStyles } from './core'
         | 
| 5 | 
            +
            import type { UnistylesRuntime } from '../core'
         | 
| 5 6 |  | 
| 6 7 | 
             
            type ExtractTransformArray<T> = T extends object
         | 
| 7 8 | 
             
                ? { [K in keyof T]: ExtractBreakpoints<T[K]> }
         | 
| @@ -56,6 +57,6 @@ type ParseStyleKeys<T> = T extends object | |
| 56 57 | 
             
                ? { [K in keyof T]: ParseNestedObject<T[K]> }
         | 
| 57 58 | 
             
                : never
         | 
| 58 59 |  | 
| 59 | 
            -
            export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme) => infer R
         | 
| 60 | 
            +
            export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme, runtime: UnistylesRuntime) => infer R
         | 
| 60 61 | 
             
                ? ParseStyleKeys<R>
         | 
| 61 62 | 
             
                : ParseStyleKeys<T>
         | 
    
        package/src/types/stylesheet.ts
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
         | 
| 2 2 | 
             
            import type { ShadowOffset, TransformStyles, UnistylesTheme } from './core'
         | 
| 3 3 | 
             
            import type { UnistylesBreakpoints } from '../global'
         | 
| 4 | 
            +
            import type { UnistylesRuntime } from '../core'
         | 
| 4 5 |  | 
| 5 6 | 
             
            // these props are treated differently to nest breakpoints and media queries
         | 
| 6 7 | 
             
            type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
         | 
| @@ -46,4 +47,4 @@ export type StyleSheet = { | |
| 46 47 | 
             
                [styleName: string]: UnistylesValues | ((...args: any) => UnistylesValues)
         | 
| 47 48 | 
             
            }
         | 
| 48 49 |  | 
| 49 | 
            -
            export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme) => StyleSheet) | StyleSheet
         | 
| 50 | 
            +
            export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme, runtime: UnistylesRuntime) => StyleSheet) | StyleSheet
         | 
    
        package/src/useStyles.ts
    CHANGED
    
    | @@ -26,7 +26,7 @@ export const useStyles = <ST extends StyleSheetWithSuperPowers>( | |
| 26 26 | 
             
                const { theme, layout, plugins } = useUnistyles()
         | 
| 27 27 | 
             
                const variants = useVariants(variantsMap)
         | 
| 28 28 | 
             
                const parsedStyles = useMemo(() => typeof stylesheet === 'function'
         | 
| 29 | 
            -
                    ? stylesheet(theme)
         | 
| 29 | 
            +
                    ? stylesheet(theme, unistyles.runtime)
         | 
| 30 30 | 
             
                    : stylesheet, [theme, stylesheet, layout])
         | 
| 31 31 |  | 
| 32 32 | 
             
                const dynamicStyleSheet = useMemo(() => Object
         | 
| @@ -18,8 +18,7 @@ using namespace winrt::Windows::UI::Core; | |
| 18 18 | 
             
            using namespace facebook;
         | 
| 19 19 |  | 
| 20 20 | 
             
            struct UIInitialInfo {
         | 
| 21 | 
            -
                 | 
| 22 | 
            -
                int screenHeight;
         | 
| 21 | 
            +
                Dimensions screen;
         | 
| 23 22 | 
             
                std::string colorScheme;
         | 
| 24 23 | 
             
                std::string contentSizeCategory;
         | 
| 25 24 | 
             
            };
         | 
| @@ -39,7 +38,9 @@ struct Unistyles { | |
| 39 38 | 
             
                            auto bounds = Window::Current().Bounds();
         | 
| 40 39 |  | 
| 41 40 | 
             
                            if (this->unistylesRuntime != nullptr) {
         | 
| 42 | 
            -
                                ( | 
| 41 | 
            +
                                Dimensions screenDimensions = Dimensions{(int)bounds.Width, (int)bounds.Height};
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                                ((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange(screenDimensions, this->getInsets(), this->getStatusBarDimensions(), this->getNavigationBarDimensions());
         | 
| 43 44 | 
             
                            }
         | 
| 44 45 | 
             
                        }));
         | 
| 45 46 |  | 
| @@ -80,8 +81,7 @@ struct Unistyles { | |
| 80 81 | 
             
                        UIInitialInfo uiMetadata;
         | 
| 81 82 | 
             
                        auto bounds = Window::Current().Bounds();
         | 
| 82 83 |  | 
| 83 | 
            -
                        uiMetadata. | 
| 84 | 
            -
                        uiMetadata.screenHeight = bounds.Height;
         | 
| 84 | 
            +
                        uiMetadata.screen = Dimensions{(int)bounds.Width, (int)bounds.Height};
         | 
| 85 85 | 
             
                        uiMetadata.colorScheme = this->getColorScheme();
         | 
| 86 86 | 
             
                        uiMetadata.contentSizeCategory = UnistylesUnspecifiedScheme;
         | 
| 87 87 |  | 
| @@ -91,12 +91,12 @@ struct Unistyles { | |
| 91 91 | 
             
                    UIInitialInfo uiInfo = uiInfoFuture.get();
         | 
| 92 92 |  | 
| 93 93 | 
             
                    auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
         | 
| 94 | 
            -
                        uiInfo. | 
| 95 | 
            -
                        uiInfo.screenHeight,
         | 
| 94 | 
            +
                        uiInfo.screen,
         | 
| 96 95 | 
             
                        uiInfo.colorScheme,
         | 
| 97 96 | 
             
                        uiInfo.contentSizeCategory,
         | 
| 98 97 | 
             
                        this->getInsets(),
         | 
| 99 | 
            -
                        this->getStatusBarDimensions()
         | 
| 98 | 
            +
                        this->getStatusBarDimensions(),
         | 
| 99 | 
            +
                        this->getNavigationBarDimensions()
         | 
| 100 100 | 
             
                    );
         | 
| 101 101 |  | 
| 102 102 | 
             
                    unistylesRuntime->onThemeChange([this](std::string theme) {
         | 
| @@ -110,16 +110,30 @@ struct Unistyles { | |
| 110 110 | 
             
                        this->OnThemeChange(payload);
         | 
| 111 111 | 
             
                    });
         | 
| 112 112 |  | 
| 113 | 
            -
                    unistylesRuntime.get()->onLayoutChange([this](std::string breakpoint, std::string orientation,  | 
| 113 | 
            +
                    unistylesRuntime.get()->onLayoutChange([this](std::string breakpoint, std::string orientation, Dimensions& screen, Dimensions& statusBar, Insets& insets, Dimensions& navigationBar) {
         | 
| 114 114 | 
             
                        auto payload = winrt::Microsoft::ReactNative::JSValueObject{
         | 
| 115 115 | 
             
                            {"type", "layout"},
         | 
| 116 116 | 
             
                            {"payload", winrt::Microsoft::ReactNative::JSValueObject{
         | 
| 117 117 | 
             
                                {"breakpoint", breakpoint},
         | 
| 118 118 | 
             
                                {"orientation", orientation},
         | 
| 119 119 | 
             
                                {"screen", winrt::Microsoft::ReactNative::JSValueObject{
         | 
| 120 | 
            -
                                    {"width", width},
         | 
| 121 | 
            -
                                    {"height", height}
         | 
| 122 | 
            -
                                }}
         | 
| 120 | 
            +
                                    {"width", screen.width},
         | 
| 121 | 
            +
                                    {"height", screen.height}
         | 
| 122 | 
            +
                                }},
         | 
| 123 | 
            +
                                {"statusBar", winrt::Microsoft::ReactNative::JSValueObject{
         | 
| 124 | 
            +
                                    {"width", statusBar.width},
         | 
| 125 | 
            +
                                    {"height", statusBar.height}
         | 
| 126 | 
            +
                                }},
         | 
| 127 | 
            +
                                {"navigationBar", winrt::Microsoft::ReactNative::JSValueObject{
         | 
| 128 | 
            +
                                    {"width", navigationBar.width},
         | 
| 129 | 
            +
                                    {"height", navigationBar.height}
         | 
| 130 | 
            +
                                }},
         | 
| 131 | 
            +
                                {"insets", winrt::Microsoft::ReactNative::JSValueObject{
         | 
| 132 | 
            +
                                    {"top", insets.top},
         | 
| 133 | 
            +
                                    {"bottom", insets.bottom},
         | 
| 134 | 
            +
                                    {"left", insets.left},
         | 
| 135 | 
            +
                                    {"right", insets.right}
         | 
| 136 | 
            +
                                }},
         | 
| 123 137 | 
             
                            }}
         | 
| 124 138 | 
             
                        };
         | 
| 125 139 |  | 
| @@ -195,24 +209,16 @@ struct Unistyles { | |
| 195 209 | 
             
                        return UnistylesUnspecifiedScheme;
         | 
| 196 210 | 
             
                    }
         | 
| 197 211 |  | 
| 198 | 
            -
                     | 
| 199 | 
            -
                         | 
| 200 | 
            -
             | 
| 201 | 
            -
                        insets.insert({ "top", 0 });
         | 
| 202 | 
            -
                        insets.insert({ "bottom", 0 });
         | 
| 203 | 
            -
                        insets.insert({ "left", 0 });
         | 
| 204 | 
            -
                        insets.insert({ "right", 0 });
         | 
| 205 | 
            -
             | 
| 206 | 
            -
                        return insets;
         | 
| 212 | 
            +
                    Insets getInsets() {
         | 
| 213 | 
            +
                        return Insets{ 0, 0, 0, 0 };
         | 
| 207 214 | 
             
                    }
         | 
| 208 215 |  | 
| 209 | 
            -
                     | 
| 210 | 
            -
                         | 
| 211 | 
            -
             | 
| 212 | 
            -
                        statusBar.insert({ "height", 0 });
         | 
| 213 | 
            -
                        statusBar.insert({ "width", 0 });
         | 
| 216 | 
            +
                    Dimensions getStatusBarDimensions() {
         | 
| 217 | 
            +
                        return {0, 0};
         | 
| 218 | 
            +
                    }
         | 
| 214 219 |  | 
| 215 | 
            -
             | 
| 220 | 
            +
                    Dimensions getNavigationBarDimensions() {
         | 
| 221 | 
            +
                        return { 0, 0 };
         | 
| 216 222 | 
             
                    }
         | 
| 217 223 | 
             
            };
         | 
| 218 224 |  |