react-native-unistyles 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -26
- package/android/CMakeLists.txt +18 -2
- package/android/build.gradle +5 -1
- package/android/src/main/cxx/cpp-adapter.cpp +16 -80
- package/android/src/main/cxx/helpers.cpp +61 -0
- package/android/src/main/cxx/helpers.h +7 -0
- package/android/src/main/cxx/platform.cpp +170 -0
- package/android/src/main/cxx/platform.h +20 -0
- package/android/src/main/java/com/unistyles/Models.kt +12 -70
- package/android/src/main/java/com/unistyles/Platform.kt +311 -10
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +145 -153
- package/cxx/Macros.h +11 -0
- package/cxx/UnistylesImpl.cpp +310 -0
- package/cxx/UnistylesModel.cpp +234 -0
- package/cxx/UnistylesModel.h +141 -0
- package/cxx/UnistylesRuntime.cpp +17 -356
- package/cxx/UnistylesRuntime.h +71 -87
- package/ios/UnistylesModule.h +13 -0
- package/ios/UnistylesModule.mm +20 -90
- package/ios/platform/Platform_Shared.h +8 -0
- package/ios/platform/Platform_Shared.mm +160 -0
- package/ios/platform/Platform_iOS.h +6 -10
- package/ios/platform/Platform_iOS.mm +143 -93
- package/ios/platform/Platform_macOS.h +3 -7
- package/ios/platform/Platform_macOS.mm +52 -34
- package/ios/platform/Platform_tvOS.h +17 -0
- package/ios/platform/Platform_tvOS.mm +96 -0
- package/ios/platform/Platform_visionOS.h +20 -0
- package/ios/platform/Platform_visionOS.mm +120 -0
- package/lib/commonjs/UnistylesProvider.js +32 -0
- package/lib/commonjs/UnistylesProvider.js.map +1 -0
- package/lib/commonjs/common.js +3 -2
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/UnistyleRegistry.js +14 -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/UnistylesModule.js +52 -8
- package/lib/commonjs/core/UnistylesModule.js.map +1 -1
- package/lib/commonjs/core/UnistylesModule.native.js.map +1 -1
- package/lib/commonjs/core/UnistylesModule.windows.js.map +1 -1
- package/lib/commonjs/core/UnistylesRuntime.js +114 -4
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/mocks/UnistylesMockedBridge.js +36 -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 +122 -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/createStyleSheet.js.map +1 -1
- package/lib/commonjs/global.js.map +1 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/useCSS.js.map +1 -1
- package/lib/commonjs/hooks/useCSS.native.js.map +1 -1
- package/lib/commonjs/hooks/useInitialTheme.js.map +1 -1
- package/lib/commonjs/hooks/useSharedContext.js +77 -0
- package/lib/commonjs/hooks/useSharedContext.js.map +1 -0
- package/lib/commonjs/hooks/useUnistyles.js +18 -65
- package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
- package/lib/commonjs/hooks/useVariants.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/normalizer/index.js.map +1 -1
- package/lib/commonjs/normalizer/module.d.js.map +1 -1
- package/lib/commonjs/normalizer/normalizeStyle.js.map +1 -1
- package/lib/commonjs/normalizer/normalizer.js +1 -1
- package/lib/commonjs/normalizer/normalizer.js.map +1 -1
- package/lib/commonjs/normalizer/normalizer.macos.js.map +1 -1
- package/lib/commonjs/plugins/cssMediaQueriesPlugin.js.map +1 -1
- package/lib/commonjs/plugins/index.js.map +1 -1
- package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +1 -1
- package/lib/commonjs/types/breakpoints.js.map +1 -1
- package/lib/commonjs/types/color.js +2 -0
- package/lib/commonjs/types/color.js.map +1 -0
- package/lib/commonjs/types/common.js.map +1 -1
- package/lib/commonjs/types/core.js.map +1 -1
- package/lib/commonjs/types/index.js +11 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/types/normalizer.js.map +1 -1
- package/lib/commonjs/types/plugin.js.map +1 -1
- package/lib/commonjs/types/stylesheet.js.map +1 -1
- package/lib/commonjs/types/unistyles.js.map +1 -1
- package/lib/commonjs/types/variants.js.map +1 -1
- package/lib/commonjs/useStyles.js +1 -1
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/cssMediaQuery.js.map +1 -1
- package/lib/commonjs/utils/generateId.js.map +1 -1
- package/lib/commonjs/utils/hash32.js.map +1 -1
- package/lib/commonjs/utils/index.js +7 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mq.js.map +1 -1
- package/lib/commonjs/utils/mqParser.js.map +1 -1
- package/lib/commonjs/utils/parseColor.js +35 -0
- package/lib/commonjs/utils/parseColor.js.map +1 -0
- package/lib/commonjs/utils/styles.js +15 -1
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/withPlugins.js.map +1 -1
- package/lib/module/UnistylesProvider.js +24 -0
- package/lib/module/UnistylesProvider.js.map +1 -0
- package/lib/module/common.js +2 -1
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/UnistyleRegistry.js +15 -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/UnistylesModule.js +52 -8
- package/lib/module/core/UnistylesModule.js.map +1 -1
- package/lib/module/core/UnistylesModule.native.js.map +1 -1
- package/lib/module/core/UnistylesModule.windows.js.map +1 -1
- package/lib/module/core/UnistylesRuntime.js +115 -4
- package/lib/module/core/UnistylesRuntime.js.map +1 -1
- package/lib/module/core/index.js +2 -1
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/mocks/UnistylesMockedBridge.js +29 -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 +114 -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/createStyleSheet.js.map +1 -1
- package/lib/module/global.js.map +1 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/useCSS.js.map +1 -1
- package/lib/module/hooks/useCSS.native.js.map +1 -1
- package/lib/module/hooks/useInitialTheme.js.map +1 -1
- package/lib/module/hooks/useSharedContext.js +70 -0
- package/lib/module/hooks/useSharedContext.js.map +1 -0
- package/lib/module/hooks/useUnistyles.js +19 -66
- package/lib/module/hooks/useUnistyles.js.map +1 -1
- package/lib/module/hooks/useVariants.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/normalizer/index.js.map +1 -1
- package/lib/module/normalizer/module.d.js.map +1 -1
- package/lib/module/normalizer/normalizeStyle.js.map +1 -1
- package/lib/module/normalizer/normalizer.js.map +1 -1
- package/lib/module/normalizer/normalizer.macos.js.map +1 -1
- package/lib/module/plugins/cssMediaQueriesPlugin.js.map +1 -1
- package/lib/module/plugins/index.js.map +1 -1
- package/lib/module/plugins/normalizeWebStylesPlugin.js.map +1 -1
- package/lib/module/types/breakpoints.js.map +1 -1
- package/lib/module/types/color.js +2 -0
- package/lib/module/types/color.js.map +1 -0
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/types/core.js.map +1 -1
- package/lib/module/types/index.js +1 -0
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/types/normalizer.js.map +1 -1
- package/lib/module/types/plugin.js.map +1 -1
- package/lib/module/types/stylesheet.js.map +1 -1
- package/lib/module/types/unistyles.js.map +1 -1
- package/lib/module/types/variants.js.map +1 -1
- package/lib/module/useStyles.js +1 -1
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/cssMediaQuery.js.map +1 -1
- package/lib/module/utils/generateId.js.map +1 -1
- package/lib/module/utils/hash32.js.map +1 -1
- package/lib/module/utils/index.js +1 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mq.js.map +1 -1
- package/lib/module/utils/mqParser.js.map +1 -1
- package/lib/module/utils/parseColor.js +28 -0
- package/lib/module/utils/parseColor.js.map +1 -0
- package/lib/module/utils/styles.js +15 -1
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/withPlugins.js.map +1 -1
- package/lib/typescript/src/UnistylesProvider.d.ts +20 -0
- package/lib/typescript/src/UnistylesProvider.d.ts.map +1 -0
- package/lib/typescript/src/common.d.ts +3 -2
- 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/UnistylesModule.d.ts +1 -0
- package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistylesModule.windows.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +84 -8
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
- package/lib/typescript/src/core/index.d.ts +3 -1
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts +28 -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 +79 -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/createStyleSheet.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useSharedContext.d.ts +33 -0
- package/lib/typescript/src/hooks/useSharedContext.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useUnistyles.d.ts +4 -19
- package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +7 -15
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/normalizer/normalizeStyle.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +9 -8
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/color.d.ts +4 -0
- package/lib/typescript/src/types/color.d.ts.map +1 -0
- package/lib/typescript/src/types/core.d.ts +2 -2
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +2 -1
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/normalizer.d.ts +1 -1
- package/lib/typescript/src/types/normalizer.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +9 -6
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/types/unistyles.d.ts +20 -9
- package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
- package/lib/typescript/src/useStyles.d.ts +1 -1
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mqParser.d.ts.map +1 -1
- package/lib/typescript/src/utils/parseColor.d.ts +3 -0
- package/lib/typescript/src/utils/parseColor.d.ts.map +1 -0
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/package.json +38 -25
- package/react-native-unistyles.podspec +4 -1
- package/src/UnistylesProvider.tsx +33 -0
- package/src/common.ts +3 -2
- package/src/core/UnistyleRegistry.ts +19 -5
- package/src/core/Unistyles.ts +10 -1
- package/src/core/UnistylesModule.ts +61 -14
- package/src/core/UnistylesRuntime.ts +120 -5
- package/src/core/index.ts +7 -1
- package/src/core/mocks/UnistylesMockedBridge.ts +30 -0
- package/src/core/mocks/UnistylesMockedRegistry.ts +47 -0
- package/src/core/mocks/UnistylesMockedRuntime.ts +144 -0
- package/src/core/mocks/index.ts +3 -0
- package/src/hooks/useSharedContext.ts +83 -0
- package/src/hooks/useUnistyles.ts +15 -71
- package/src/index.ts +10 -4
- package/src/types/breakpoints.ts +19 -9
- package/src/types/color.ts +26 -0
- package/src/types/core.ts +2 -2
- package/src/types/index.ts +5 -1
- package/src/types/normalizer.ts +1 -1
- package/src/types/stylesheet.ts +10 -7
- package/src/types/unistyles.ts +28 -12
- package/src/useStyles.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/parseColor.ts +33 -0
- package/src/utils/styles.ts +24 -1
- package/windows/ExperimentalFeatures.props +4 -4
- package/windows/NuGet.Config +0 -1
- package/windows/ReactNativeUnistyles/ReactNativeUnistyles.h +42 -118
- package/windows/ReactNativeUnistyles/ReactNativeUnistyles.vcxproj +7 -2
- package/windows/ReactNativeUnistyles/ReactNativeUnistyles.vcxproj.filters +6 -1
- package/windows/ReactNativeUnistyles/packages.lock.json +31 -31
- package/android/src/main/java/com/unistyles/Config.kt +0 -116
- package/android/src/main/java/com/unistyles/Insets.kt +0 -138
- package/ios/UnistylesHelpers.h +0 -3
- package/ios/UnistylesHelpers.mm +0 -5
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { Color } from '../types'
|
2
|
+
import { isIOS } from '../common'
|
3
|
+
|
4
|
+
const parseAlpha = (alpha: number) => {
|
5
|
+
if (alpha > 1 || alpha < 0) {
|
6
|
+
return 1
|
7
|
+
}
|
8
|
+
|
9
|
+
return alpha
|
10
|
+
}
|
11
|
+
|
12
|
+
export const parseColor = (color?: Color, alpha: number = 1): [string, number] => {
|
13
|
+
if (!color) {
|
14
|
+
return ['', 1]
|
15
|
+
}
|
16
|
+
|
17
|
+
// ignore alpha for 8 digit hex colors
|
18
|
+
if (color.startsWith('#') && color.length === 9) {
|
19
|
+
return [color, 1]
|
20
|
+
}
|
21
|
+
|
22
|
+
if (color.startsWith('#') && color.length === 7) {
|
23
|
+
return [color, parseAlpha(alpha)]
|
24
|
+
}
|
25
|
+
|
26
|
+
if (isIOS && color === 'transparent') {
|
27
|
+
return ['#000000', 0]
|
28
|
+
}
|
29
|
+
|
30
|
+
// todo remove this with Unistyles 3.0
|
31
|
+
// named colors
|
32
|
+
return [color, 1]
|
33
|
+
}
|
package/src/utils/styles.ts
CHANGED
@@ -35,7 +35,30 @@ export const parseStyle = <T extends RNStyle>(
|
|
35
35
|
|
36
36
|
// transforms
|
37
37
|
if (key === 'transform' && Array.isArray(value)) {
|
38
|
-
acc[key] = value
|
38
|
+
acc[key] = value
|
39
|
+
.map(value => parseStyle(value, variant))
|
40
|
+
.filter(value => {
|
41
|
+
// remove undefined values
|
42
|
+
if (typeof value === 'object') {
|
43
|
+
return Object.values(value).at(0) !== undefined
|
44
|
+
}
|
45
|
+
|
46
|
+
return true
|
47
|
+
})
|
48
|
+
|
49
|
+
return acc
|
50
|
+
}
|
51
|
+
|
52
|
+
if ((key === 'boxShadow' || key === 'filter') && Array.isArray(value)) {
|
53
|
+
acc[key] = value
|
54
|
+
.map(value => parseStyle(value, variant, false))
|
55
|
+
.filter(value => Object.keys(value).length === 1)
|
56
|
+
|
57
|
+
return acc
|
58
|
+
}
|
59
|
+
|
60
|
+
if (key === 'fontVariant' && Array.isArray(value)) {
|
61
|
+
acc[key] = value
|
39
62
|
|
40
63
|
return acc
|
41
64
|
}
|
@@ -2,10 +2,10 @@
|
|
2
2
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
3
3
|
|
4
4
|
<!--
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
This file contains some important settings that will apply globally for
|
6
|
+
your app and *all* native modules your app consumes. These values were
|
7
|
+
set when you created the app project, and in some cases cannot be
|
8
|
+
simply changed here without recreating a new project.
|
9
9
|
-->
|
10
10
|
|
11
11
|
<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
|
package/windows/NuGet.Config
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
</config>
|
6
6
|
<packageSources>
|
7
7
|
<clear />
|
8
|
-
<add key="react-native" value="https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/nuget/v3/index.json" />
|
9
8
|
<add key="Nuget.org" value="https://api.nuget.org/v3/index.json" />
|
10
9
|
</packageSources>
|
11
10
|
<disabledPackageSources>
|
@@ -8,21 +8,18 @@
|
|
8
8
|
#include <winrt/Microsoft.ReactNative.h>
|
9
9
|
#include <winrt/Windows.UI.Xaml.h>
|
10
10
|
#include <winrt/Windows.UI.Core.h>
|
11
|
+
#include <winrt/Windows.Graphics.Display.h>
|
11
12
|
#include <winrt/Windows.UI.ViewManagement.h>
|
12
13
|
#include "UnistylesRuntime.h"
|
14
|
+
#include <TurboModuleProvider.h>
|
13
15
|
|
14
16
|
using namespace winrt::Windows::UI::ViewManagement;
|
17
|
+
using namespace winrt::Windows::Graphics::Display;
|
15
18
|
using namespace winrt::Microsoft::ReactNative;
|
16
19
|
using namespace winrt::Windows::UI::Xaml;
|
17
20
|
using namespace winrt::Windows::UI::Core;
|
18
21
|
using namespace facebook;
|
19
22
|
|
20
|
-
struct UIInitialInfo {
|
21
|
-
Dimensions screen;
|
22
|
-
std::string colorScheme;
|
23
|
-
std::string contentSizeCategory;
|
24
|
-
};
|
25
|
-
|
26
23
|
namespace winrt::ReactNativeUnistyles
|
27
24
|
{
|
28
25
|
|
@@ -30,157 +27,86 @@ REACT_MODULE(Unistyles, L"Unistyles")
|
|
30
27
|
struct Unistyles {
|
31
28
|
|
32
29
|
REACT_INIT(Initialize)
|
33
|
-
|
30
|
+
void Initialize(ReactContext const& reactContext) noexcept {
|
34
31
|
m_reactContext = reactContext;
|
35
32
|
|
36
33
|
m_reactContext.UIDispatcher().Post([this]() mutable {
|
37
34
|
this->windowSizeChange = Window::Current().CoreWindow().SizeChanged(TypedEventHandler<CoreWindow, WindowSizeChangedEventArgs>([=](CoreWindow const sender, WindowSizeChangedEventArgs const&) {
|
38
|
-
auto bounds = Window::Current().Bounds();
|
39
|
-
|
40
35
|
if (this->unistylesRuntime != nullptr) {
|
41
|
-
|
42
|
-
|
43
|
-
((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange(screenDimensions, this->getInsets(), this->getStatusBarDimensions(), this->getNavigationBarDimensions());
|
36
|
+
((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange(getScreenDimensions(), std::nullopt, std::nullopt, std::nullopt);
|
44
37
|
}
|
45
38
|
}));
|
46
39
|
|
47
|
-
UISettings
|
48
|
-
|
49
|
-
this->colorValuesChange = settings.ColorValuesChanged(TypedEventHandler<UISettings, IInspectable>([this](UISettings const& sender, IInspectable const&){
|
40
|
+
this->colorValuesChange = UISettings().ColorValuesChanged(TypedEventHandler<UISettings, IInspectable>([this](UISettings const& sender, IInspectable const&) {
|
50
41
|
if (this->unistylesRuntime != nullptr) {
|
51
42
|
((UnistylesRuntime*)this->unistylesRuntime)->handleAppearanceChange(this->getColorScheme());
|
52
43
|
}
|
53
44
|
}));
|
54
45
|
});
|
55
46
|
}
|
56
|
-
|
47
|
+
|
57
48
|
REACT_SYNC_METHOD(install)
|
58
|
-
|
49
|
+
bool install() noexcept {
|
59
50
|
if (m_reactContext == nullptr) {
|
60
51
|
return false;
|
61
52
|
}
|
62
53
|
|
63
54
|
jsi::Runtime* jsiRuntime = TryGetOrCreateContextRuntime(m_reactContext);
|
64
|
-
|
55
|
+
|
65
56
|
if (jsiRuntime == nullptr) {
|
66
57
|
return false;
|
67
58
|
}
|
68
59
|
|
69
60
|
auto& runtime = *jsiRuntime;
|
61
|
+
auto callInvoker = MakeAbiCallInvoker(m_reactContext.Handle().JSDispatcher());
|
70
62
|
|
71
|
-
registerUnistylesHostObject(runtime);
|
63
|
+
registerUnistylesHostObject(runtime, callInvoker);
|
72
64
|
|
73
65
|
return true;
|
74
66
|
}
|
75
67
|
|
76
|
-
void registerUnistylesHostObject(jsi::Runtime& runtime) {
|
77
|
-
std::
|
78
|
-
auto uiInfoFuture = uiInfoPromise.get_future();
|
79
|
-
|
80
|
-
m_reactContext.UIDispatcher().Post([this, promise = std::move(uiInfoPromise)]() mutable {
|
81
|
-
UIInitialInfo uiMetadata;
|
82
|
-
auto bounds = Window::Current().Bounds();
|
68
|
+
void registerUnistylesHostObject(jsi::Runtime& runtime, std::shared_ptr<facebook::react::CallInvoker> callInvoker) {
|
69
|
+
auto unistylesRuntime = std::make_shared<UnistylesRuntime>(runtime, callInvoker);
|
83
70
|
|
84
|
-
|
85
|
-
uiMetadata.colorScheme = this->getColorScheme();
|
86
|
-
uiMetadata.contentSizeCategory = UnistylesUnspecifiedScheme;
|
87
|
-
|
88
|
-
promise.set_value(std::move(uiMetadata));
|
89
|
-
});
|
90
|
-
|
91
|
-
UIInitialInfo uiInfo = uiInfoFuture.get();
|
71
|
+
this->unistylesRuntime = unistylesRuntime.get();
|
92
72
|
|
93
|
-
|
94
|
-
uiInfo.screen,
|
95
|
-
uiInfo.colorScheme,
|
96
|
-
uiInfo.contentSizeCategory,
|
97
|
-
this->getInsets(),
|
98
|
-
this->getStatusBarDimensions(),
|
99
|
-
this->getNavigationBarDimensions()
|
100
|
-
);
|
73
|
+
makeShared((UnistylesRuntime*)unistylesRuntime.get());
|
101
74
|
|
102
|
-
|
103
|
-
winrt::hstring themeName = winrt::to_hstring(theme);
|
75
|
+
auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
|
104
76
|
|
105
|
-
|
106
|
-
|
107
|
-
{"payload", winrt::Microsoft::ReactNative::JSValueObject{{"themeName", winrt::to_string(themeName)}}}
|
108
|
-
};
|
77
|
+
runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
|
78
|
+
}
|
109
79
|
|
110
|
-
|
80
|
+
void makeShared(UnistylesRuntime* unistylesRuntime) {
|
81
|
+
unistylesRuntime->setScreenDimensionsCallback([this]() {
|
82
|
+
return getScreenDimensions();
|
111
83
|
});
|
112
84
|
|
113
|
-
unistylesRuntime
|
114
|
-
|
115
|
-
{"type", "layout"},
|
116
|
-
{"payload", winrt::Microsoft::ReactNative::JSValueObject{
|
117
|
-
{"breakpoint", breakpoint},
|
118
|
-
{"orientation", orientation},
|
119
|
-
{"screen", winrt::Microsoft::ReactNative::JSValueObject{
|
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
|
-
}},
|
137
|
-
}}
|
138
|
-
};
|
139
|
-
|
140
|
-
this->OnLayoutChange(payload);
|
85
|
+
unistylesRuntime->setColorSchemeCallback([this]() {
|
86
|
+
return getColorScheme();
|
141
87
|
});
|
142
88
|
|
143
|
-
|
144
|
-
auto
|
145
|
-
{"type", "plugin"}
|
146
|
-
};
|
89
|
+
m_reactContext.UIDispatcher().Post([this, unistylesRuntime]() {
|
90
|
+
auto screen = getScreenDimensions();
|
147
91
|
|
148
|
-
|
92
|
+
unistylesRuntime->screen = Dimensions({ screen.width, screen.height });
|
93
|
+
unistylesRuntime->pixelRatio = screen.pixelRatio;
|
94
|
+
unistylesRuntime->fontScale = screen.fontScale;
|
95
|
+
unistylesRuntime->colorScheme = getColorScheme();
|
149
96
|
});
|
150
|
-
|
151
|
-
unistylesRuntime.get()->onContentSizeCategoryChange([this](std::string contentSizeCategory) {
|
152
|
-
// not available on windows
|
153
|
-
});
|
154
|
-
|
155
|
-
this->unistylesRuntime = unistylesRuntime.get();
|
156
|
-
|
157
|
-
auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
|
158
|
-
|
159
|
-
runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
|
160
97
|
}
|
161
98
|
|
162
|
-
REACT_EVENT(OnThemeChange, L"__unistylesOnChange")
|
163
|
-
std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnThemeChange;
|
164
|
-
|
165
|
-
REACT_EVENT(OnLayoutChange, L"__unistylesOnChange")
|
166
|
-
std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnLayoutChange;
|
167
|
-
|
168
|
-
REACT_EVENT(OnPluginChange, L"__unistylesOnChange")
|
169
|
-
std::function<void(winrt::Microsoft::ReactNative::JSValueObject const&)> OnPluginChange;
|
170
|
-
|
171
99
|
~Unistyles() {
|
172
100
|
if (this->unistylesRuntime != nullptr) {
|
173
101
|
this->unistylesRuntime = nullptr;
|
174
102
|
}
|
175
103
|
|
176
104
|
if (this->windowSizeChange) {
|
177
|
-
|
105
|
+
this->windowSizeChange = { NULL };
|
178
106
|
}
|
179
107
|
|
180
108
|
if (this->colorValuesChange) {
|
181
|
-
|
182
|
-
|
183
|
-
settings.ColorValuesChanged(this->colorValuesChange);
|
109
|
+
this->colorValuesChange = { NULL };
|
184
110
|
}
|
185
111
|
}
|
186
112
|
|
@@ -191,16 +117,17 @@ struct Unistyles {
|
|
191
117
|
winrt::event_token colorValuesChange{ NULL };
|
192
118
|
|
193
119
|
std::string getColorScheme() {
|
194
|
-
|
195
|
-
|
120
|
+
UISettings uiSettings;
|
121
|
+
|
122
|
+
auto backgroundColor = uiSettings.GetColorValue(UIColorType::Background);
|
196
123
|
|
197
|
-
bool isDark =
|
124
|
+
bool isDark = backgroundColor == Colors::Black();
|
198
125
|
|
199
126
|
if (isDark) {
|
200
127
|
return UnistylesDarkScheme;
|
201
128
|
}
|
202
129
|
|
203
|
-
bool isLight =
|
130
|
+
bool isLight = backgroundColor == Colors::White();
|
204
131
|
|
205
132
|
if (isLight) {
|
206
133
|
return UnistylesLightScheme;
|
@@ -209,16 +136,13 @@ struct Unistyles {
|
|
209
136
|
return UnistylesUnspecifiedScheme;
|
210
137
|
}
|
211
138
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
return {0, 0};
|
218
|
-
}
|
139
|
+
Screen getScreenDimensions() {
|
140
|
+
auto bounds = Window::Current().Bounds();
|
141
|
+
auto displayInfo = DisplayInformation::GetForCurrentView();
|
142
|
+
auto pixelRatio = displayInfo.LogicalDpi() / 96.0f;
|
143
|
+
float fontScale = UISettings().TextScaleFactor();
|
219
144
|
|
220
|
-
|
221
|
-
return { 0, 0 };
|
145
|
+
return Screen({ (int)bounds.Width, (int)bounds.Height, pixelRatio, fontScale });
|
222
146
|
}
|
223
147
|
};
|
224
148
|
|
@@ -79,7 +79,7 @@
|
|
79
79
|
<PropertyGroup Label="UserMacros" />
|
80
80
|
<ItemDefinitionGroup>
|
81
81
|
<ClCompile>
|
82
|
-
<PrecompiledHeader>
|
82
|
+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
83
83
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
84
84
|
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
|
85
85
|
<WarningLevel>Level4</WarningLevel>
|
@@ -112,6 +112,9 @@
|
|
112
112
|
</ClCompile>
|
113
113
|
</ItemDefinitionGroup>
|
114
114
|
<ItemGroup>
|
115
|
+
<ClInclude Include="..\..\cxx\Macros.h" />
|
116
|
+
<ClInclude Include="..\..\cxx\UnistylesModel.h" />
|
117
|
+
<ClInclude Include="..\..\cxx\UnistylesRuntime.h" />
|
115
118
|
<ClInclude Include="ReactPackageProvider.h">
|
116
119
|
<DependentUpon>ReactPackageProvider.idl</DependentUpon>
|
117
120
|
</ClInclude>
|
@@ -119,6 +122,8 @@
|
|
119
122
|
<ClInclude Include="pch.h" />
|
120
123
|
</ItemGroup>
|
121
124
|
<ItemGroup>
|
125
|
+
<ClCompile Include="..\..\cxx\UnistylesImpl.cpp" />
|
126
|
+
<ClCompile Include="..\..\cxx\UnistylesModel.cpp" />
|
122
127
|
<ClCompile Include="..\..\cxx\UnistylesRuntime.cpp">
|
123
128
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">NotUsing</PrecompiledHeader>
|
124
129
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
@@ -154,4 +159,4 @@
|
|
154
159
|
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props'))" />
|
155
160
|
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets'))" />
|
156
161
|
</Target>
|
157
|
-
</Project>
|
162
|
+
</Project>
|
@@ -8,13 +8,18 @@
|
|
8
8
|
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
|
9
9
|
<ClCompile Include="ReactPackageProvider.cpp" />
|
10
10
|
<ClCompile Include="..\..\cxx\UnistylesRuntime.cpp" />
|
11
|
+
<ClCompile Include="..\..\cxx\UnistylesImpl.cpp" />
|
12
|
+
<ClCompile Include="..\..\cxx\UnistylesModel.cpp" />
|
11
13
|
</ItemGroup>
|
12
14
|
<ItemGroup>
|
13
15
|
<ClInclude Include="pch.h" />
|
14
16
|
<ClInclude Include="ReactPackageProvider.h" />
|
15
17
|
<ClInclude Include="ReactNativeUnistyles.h" />
|
18
|
+
<ClInclude Include="..\..\cxx\Macros.h" />
|
19
|
+
<ClInclude Include="..\..\cxx\UnistylesModel.h" />
|
20
|
+
<ClInclude Include="..\..\cxx\UnistylesRuntime.h" />
|
16
21
|
</ItemGroup>
|
17
22
|
<ItemGroup>
|
18
23
|
<None Include="PropertySheet.props" />
|
19
24
|
</ItemGroup>
|
20
|
-
</Project>
|
25
|
+
</Project>
|
@@ -4,17 +4,17 @@
|
|
4
4
|
"native,Version=v0.0": {
|
5
5
|
"Microsoft.ReactNative": {
|
6
6
|
"type": "Direct",
|
7
|
-
"requested": "[0.
|
8
|
-
"resolved": "0.
|
9
|
-
"contentHash": "
|
7
|
+
"requested": "[0.74.9, )",
|
8
|
+
"resolved": "0.74.9",
|
9
|
+
"contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
|
10
10
|
},
|
11
11
|
"Microsoft.ReactNative.Cxx": {
|
12
12
|
"type": "Direct",
|
13
|
-
"requested": "[0.
|
14
|
-
"resolved": "0.
|
15
|
-
"contentHash": "
|
13
|
+
"requested": "[0.74.9, )",
|
14
|
+
"resolved": "0.74.9",
|
15
|
+
"contentHash": "C+Z2fmjDc7SJXeOWyD/9ImqooU7yX3ALB1Yno2UNYo+Li2SImeG6DdEfcNfSCS2fek1R3znpd6yNEkar/t1n5w==",
|
16
16
|
"dependencies": {
|
17
|
-
"Microsoft.ReactNative": "0.
|
17
|
+
"Microsoft.ReactNative": "0.74.9"
|
18
18
|
}
|
19
19
|
},
|
20
20
|
"Microsoft.UI.Xaml": {
|
@@ -28,9 +28,9 @@
|
|
28
28
|
},
|
29
29
|
"Microsoft.Windows.CppWinRT": {
|
30
30
|
"type": "Direct",
|
31
|
-
"requested": "[2.0.
|
32
|
-
"resolved": "2.0.
|
33
|
-
"contentHash": "
|
31
|
+
"requested": "[2.0.230706.1, )",
|
32
|
+
"resolved": "2.0.230706.1",
|
33
|
+
"contentHash": "l0D7oCw/5X+xIKHqZTi62TtV+1qeSz7KVluNFdrJ9hXsst4ghvqQ/Yhura7JqRdZWBXAuDS0G0KwALptdoxweQ=="
|
34
34
|
},
|
35
35
|
"Microsoft.Web.WebView2": {
|
36
36
|
"type": "Transitive",
|
@@ -41,9 +41,9 @@
|
|
41
41
|
"native,Version=v0.0/win10-arm": {
|
42
42
|
"Microsoft.ReactNative": {
|
43
43
|
"type": "Direct",
|
44
|
-
"requested": "[0.
|
45
|
-
"resolved": "0.
|
46
|
-
"contentHash": "
|
44
|
+
"requested": "[0.74.9, )",
|
45
|
+
"resolved": "0.74.9",
|
46
|
+
"contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
|
47
47
|
},
|
48
48
|
"Microsoft.Web.WebView2": {
|
49
49
|
"type": "Transitive",
|
@@ -54,9 +54,9 @@
|
|
54
54
|
"native,Version=v0.0/win10-arm-aot": {
|
55
55
|
"Microsoft.ReactNative": {
|
56
56
|
"type": "Direct",
|
57
|
-
"requested": "[0.
|
58
|
-
"resolved": "0.
|
59
|
-
"contentHash": "
|
57
|
+
"requested": "[0.74.9, )",
|
58
|
+
"resolved": "0.74.9",
|
59
|
+
"contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
|
60
60
|
},
|
61
61
|
"Microsoft.Web.WebView2": {
|
62
62
|
"type": "Transitive",
|
@@ -67,9 +67,9 @@
|
|
67
67
|
"native,Version=v0.0/win10-arm64-aot": {
|
68
68
|
"Microsoft.ReactNative": {
|
69
69
|
"type": "Direct",
|
70
|
-
"requested": "[0.
|
71
|
-
"resolved": "0.
|
72
|
-
"contentHash": "
|
70
|
+
"requested": "[0.74.9, )",
|
71
|
+
"resolved": "0.74.9",
|
72
|
+
"contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
|
73
73
|
},
|
74
74
|
"Microsoft.Web.WebView2": {
|
75
75
|
"type": "Transitive",
|
@@ -80,9 +80,9 @@
|
|
80
80
|
"native,Version=v0.0/win10-x64": {
|
81
81
|
"Microsoft.ReactNative": {
|
82
82
|
"type": "Direct",
|
83
|
-
"requested": "[0.
|
84
|
-
"resolved": "0.
|
85
|
-
"contentHash": "
|
83
|
+
"requested": "[0.74.9, )",
|
84
|
+
"resolved": "0.74.9",
|
85
|
+
"contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
|
86
86
|
},
|
87
87
|
"Microsoft.Web.WebView2": {
|
88
88
|
"type": "Transitive",
|
@@ -93,9 +93,9 @@
|
|
93
93
|
"native,Version=v0.0/win10-x64-aot": {
|
94
94
|
"Microsoft.ReactNative": {
|
95
95
|
"type": "Direct",
|
96
|
-
"requested": "[0.
|
97
|
-
"resolved": "0.
|
98
|
-
"contentHash": "
|
96
|
+
"requested": "[0.74.9, )",
|
97
|
+
"resolved": "0.74.9",
|
98
|
+
"contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
|
99
99
|
},
|
100
100
|
"Microsoft.Web.WebView2": {
|
101
101
|
"type": "Transitive",
|
@@ -106,9 +106,9 @@
|
|
106
106
|
"native,Version=v0.0/win10-x86": {
|
107
107
|
"Microsoft.ReactNative": {
|
108
108
|
"type": "Direct",
|
109
|
-
"requested": "[0.
|
110
|
-
"resolved": "0.
|
111
|
-
"contentHash": "
|
109
|
+
"requested": "[0.74.9, )",
|
110
|
+
"resolved": "0.74.9",
|
111
|
+
"contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
|
112
112
|
},
|
113
113
|
"Microsoft.Web.WebView2": {
|
114
114
|
"type": "Transitive",
|
@@ -119,9 +119,9 @@
|
|
119
119
|
"native,Version=v0.0/win10-x86-aot": {
|
120
120
|
"Microsoft.ReactNative": {
|
121
121
|
"type": "Direct",
|
122
|
-
"requested": "[0.
|
123
|
-
"resolved": "0.
|
124
|
-
"contentHash": "
|
122
|
+
"requested": "[0.74.9, )",
|
123
|
+
"resolved": "0.74.9",
|
124
|
+
"contentHash": "BmRwnI3nOZu8V78pBRQmkBfg09sKcM8dtqSUmGtH3W2auQtJjioa7cbnARkDhOb1cPCC+qELJHtQstHhSW2aoA=="
|
125
125
|
},
|
126
126
|
"Microsoft.Web.WebView2": {
|
127
127
|
"type": "Transitive",
|
@@ -1,116 +0,0 @@
|
|
1
|
-
package com.unistyles
|
2
|
-
|
3
|
-
import android.annotation.SuppressLint
|
4
|
-
import android.content.res.Configuration
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
6
|
-
|
7
|
-
class UnistylesConfig(private val reactApplicationContext: ReactApplicationContext) {
|
8
|
-
private val insets: UnistylesInsets = UnistylesInsets(reactApplicationContext)
|
9
|
-
private val density: Float = reactApplicationContext.resources.displayMetrics.density
|
10
|
-
private var lastConfig: Config = this.getAppConfig()
|
11
|
-
private var lastLayoutConfig: LayoutConfig = this.getAppLayoutConfig()
|
12
|
-
|
13
|
-
fun hasNewConfig(): Boolean {
|
14
|
-
val newConfig = this.getAppConfig()
|
15
|
-
val newContentSizeCategory = newConfig.contentSizeCategory != lastConfig.contentSizeCategory
|
16
|
-
val newColorScheme = newConfig.colorScheme != lastConfig.colorScheme
|
17
|
-
|
18
|
-
if (!newContentSizeCategory && !newColorScheme) {
|
19
|
-
return false
|
20
|
-
}
|
21
|
-
|
22
|
-
lastConfig = newConfig
|
23
|
-
lastConfig.hasNewContentSizeCategory = newContentSizeCategory
|
24
|
-
lastConfig.hasNewColorScheme = newColorScheme
|
25
|
-
|
26
|
-
return true
|
27
|
-
}
|
28
|
-
|
29
|
-
fun hasNewLayoutConfig(): Boolean {
|
30
|
-
val newConfig = this.getAppLayoutConfig()
|
31
|
-
|
32
|
-
if (newConfig.isEqual(lastLayoutConfig)) {
|
33
|
-
return false
|
34
|
-
}
|
35
|
-
|
36
|
-
lastLayoutConfig = newConfig
|
37
|
-
|
38
|
-
return true
|
39
|
-
}
|
40
|
-
|
41
|
-
fun getConfig(): Config {
|
42
|
-
return this.lastConfig
|
43
|
-
}
|
44
|
-
|
45
|
-
fun getLayoutConfig(): LayoutConfig {
|
46
|
-
return this.lastLayoutConfig
|
47
|
-
}
|
48
|
-
|
49
|
-
private fun getAppConfig(): Config {
|
50
|
-
val fontScale = reactApplicationContext.resources.configuration.fontScale
|
51
|
-
|
52
|
-
return Config(
|
53
|
-
this.getColorScheme(),
|
54
|
-
this.getContentSizeCategory(fontScale),
|
55
|
-
)
|
56
|
-
}
|
57
|
-
|
58
|
-
private fun getAppLayoutConfig(): LayoutConfig {
|
59
|
-
val displayMetrics = reactApplicationContext.resources.displayMetrics
|
60
|
-
val screenWidth = (displayMetrics.widthPixels / density).toInt()
|
61
|
-
val screenHeight = (displayMetrics.heightPixels / density).toInt()
|
62
|
-
|
63
|
-
return LayoutConfig(
|
64
|
-
Dimensions(screenWidth, screenHeight),
|
65
|
-
this.insets.get(),
|
66
|
-
Dimensions(screenWidth, getStatusBarHeight()),
|
67
|
-
Dimensions(screenWidth, getNavigationBarHeight())
|
68
|
-
)
|
69
|
-
}
|
70
|
-
|
71
|
-
private fun getContentSizeCategory(fontScale: Float): String {
|
72
|
-
val contentSizeCategory = when {
|
73
|
-
fontScale <= 0.85f -> "Small"
|
74
|
-
fontScale <= 1.0f -> "Default"
|
75
|
-
fontScale <= 1.15f -> "Large"
|
76
|
-
fontScale <= 1.3f -> "ExtraLarge"
|
77
|
-
fontScale <= 1.5f -> "Huge"
|
78
|
-
fontScale <= 1.8 -> "ExtraHuge"
|
79
|
-
else -> "ExtraExtraHuge"
|
80
|
-
}
|
81
|
-
|
82
|
-
return contentSizeCategory
|
83
|
-
}
|
84
|
-
|
85
|
-
private fun getColorScheme(): String {
|
86
|
-
val colorScheme = when (reactApplicationContext.resources.configuration.uiMode.and(Configuration.UI_MODE_NIGHT_MASK)) {
|
87
|
-
Configuration.UI_MODE_NIGHT_YES -> "dark"
|
88
|
-
Configuration.UI_MODE_NIGHT_NO -> "light"
|
89
|
-
else -> "unspecified"
|
90
|
-
}
|
91
|
-
|
92
|
-
return colorScheme
|
93
|
-
}
|
94
|
-
|
95
|
-
@SuppressLint("InternalInsetResource", "DiscouragedApi")
|
96
|
-
private fun getStatusBarHeight(): Int {
|
97
|
-
val heightResId = reactApplicationContext.resources.getIdentifier("status_bar_height", "dimen", "android")
|
98
|
-
|
99
|
-
if (heightResId > 0) {
|
100
|
-
return (reactApplicationContext.resources.getDimensionPixelSize(heightResId) / density).toInt()
|
101
|
-
}
|
102
|
-
|
103
|
-
return 0
|
104
|
-
}
|
105
|
-
|
106
|
-
@SuppressLint("InternalInsetResource", "DiscouragedApi")
|
107
|
-
private fun getNavigationBarHeight(): Int {
|
108
|
-
val heightResId = reactApplicationContext.resources.getIdentifier("navigation_bar_height", "dimen", "android")
|
109
|
-
|
110
|
-
if (heightResId > 0) {
|
111
|
-
return (reactApplicationContext.resources.getDimensionPixelSize(heightResId) / density).toInt()
|
112
|
-
}
|
113
|
-
|
114
|
-
return 0
|
115
|
-
}
|
116
|
-
}
|