@amazon-devices/expo-system-ui 2.0.1758683737
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/.eslintrc.js +2 -0
- package/CHANGELOG.md +116 -0
- package/CMakeLists.txt +46 -0
- package/LICENSE +7 -0
- package/README.kepler.md +80 -0
- package/README.md +27 -0
- package/THIRD_PARTY_NOTICES.txt +24 -0
- package/android/build.gradle +112 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/systemui/SystemUIModule.kt +74 -0
- package/android/src/main/java/expo/modules/systemui/SystemUIPackage.kt +11 -0
- package/android/src/main/java/expo/modules/systemui/SystemUIReactActivityLifecycleListener.kt +18 -0
- package/android/src/main/java/expo/modules/systemui/singletons/SystemUI.kt +36 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/app.plugin.js +1 -0
- package/build/ExpoSystemUI.d.ts +3 -0
- package/build/ExpoSystemUI.d.ts.map +1 -0
- package/build/ExpoSystemUI.js +3 -0
- package/build/ExpoSystemUI.js.map +1 -0
- package/build/ExpoSystemUI.kepler.d.ts +7 -0
- package/build/ExpoSystemUI.kepler.d.ts.map +1 -0
- package/build/ExpoSystemUI.kepler.js +14 -0
- package/build/ExpoSystemUI.kepler.js.map +1 -0
- package/build/ExpoSystemUI.web.d.ts +7 -0
- package/build/ExpoSystemUI.web.d.ts.map +1 -0
- package/build/ExpoSystemUI.web.js +22 -0
- package/build/ExpoSystemUI.web.js.map +1 -0
- package/build/SystemUI.d.ts +23 -0
- package/build/SystemUI.d.ts.map +1 -0
- package/build/SystemUI.js +34 -0
- package/build/SystemUI.js.map +1 -0
- package/expo-module.config.json +10 -0
- package/ios/ExpoSystemUI/ExpoSystemUIModule.swift +72 -0
- package/ios/ExpoSystemUI.podspec +31 -0
- package/kepler/ExpoSystemUI.cpp +47 -0
- package/kepler/ExpoSystemUI.h +29 -0
- package/kepler/ExpoSystemUIImpl.cpp +39 -0
- package/kepler/ExpoSystemUIImpl.h +29 -0
- package/kepler/ExpoSystemUITurboModule.cpp +57 -0
- package/kepler/ExpoSystemUITurboModule.h +32 -0
- package/kepler/KeplerInit.cpp +28 -0
- package/kepler/test/ExpoSystemUI.cpp +154 -0
- package/package.json +1 -0
- package/plugin/babel.config.js +1 -0
- package/plugin/build/withAndroidRootViewBackgroundColor.d.ts +6 -0
- package/plugin/build/withAndroidRootViewBackgroundColor.js +40 -0
- package/plugin/build/withAndroidUserInterfaceStyle.d.ts +8 -0
- package/plugin/build/withAndroidUserInterfaceStyle.js +42 -0
- package/plugin/build/withIosRootViewBackgroundColor.d.ts +5 -0
- package/plugin/build/withIosRootViewBackgroundColor.js +41 -0
- package/plugin/build/withIosUserInterfaceStyle.d.ts +5 -0
- package/plugin/build/withIosUserInterfaceStyle.js +38 -0
- package/plugin/build/withSystemUI.d.ts +3 -0
- package/plugin/build/withSystemUI.js +17 -0
- package/plugin/src/withAndroidRootViewBackgroundColor.ts +47 -0
- package/plugin/src/withAndroidUserInterfaceStyle.ts +53 -0
- package/plugin/src/withIosRootViewBackgroundColor.ts +41 -0
- package/plugin/src/withIosUserInterfaceStyle.ts +47 -0
- package/plugin/src/withSystemUI.ts +19 -0
- package/plugin/tsconfig.json +9 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/react-native.config.js +21 -0
- package/src/ExpoSystemUI.kepler.ts +27 -0
- package/src/ExpoSystemUI.ts +2 -0
- package/src/ExpoSystemUI.web.ts +21 -0
- package/src/SystemUI.ts +35 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExpoConfig } from 'expo/config';
|
|
2
|
+
import { AndroidConfig, ConfigPlugin } from 'expo/config-plugins';
|
|
3
|
+
export type Props = {
|
|
4
|
+
userInterfaceStyle?: ExpoConfig['userInterfaceStyle'];
|
|
5
|
+
};
|
|
6
|
+
export declare const withAndroidUserInterfaceStyle: ConfigPlugin<void>;
|
|
7
|
+
export declare function resolveProps(config: Pick<ExpoConfig, 'userInterfaceStyle' | 'android'>): Props;
|
|
8
|
+
export declare function setStrings(strings: AndroidConfig.Resources.ResourceXML, { userInterfaceStyle }: Props): AndroidConfig.Resources.ResourceXML;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withAndroidUserInterfaceStyle = void 0;
|
|
7
|
+
exports.resolveProps = resolveProps;
|
|
8
|
+
exports.setStrings = setStrings;
|
|
9
|
+
const assert_1 = __importDefault(require("assert"));
|
|
10
|
+
const config_plugins_1 = require("expo/config-plugins");
|
|
11
|
+
// strings.xml keys, this should not change.
|
|
12
|
+
const USER_INTERFACE_STYLE_KEY = 'expo_system_ui_user_interface_style';
|
|
13
|
+
const withAndroidUserInterfaceStyle = (config) => {
|
|
14
|
+
return (0, config_plugins_1.withStringsXml)(config, (config) => {
|
|
15
|
+
config.modResults = setStrings(config.modResults, resolveProps(config));
|
|
16
|
+
return config;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
exports.withAndroidUserInterfaceStyle = withAndroidUserInterfaceStyle;
|
|
20
|
+
function resolveProps(config) {
|
|
21
|
+
const userInterfaceStyle = config.android?.userInterfaceStyle ?? config.userInterfaceStyle;
|
|
22
|
+
(0, assert_1.default)(!userInterfaceStyle || ['automatic', 'light', 'dark'].includes(userInterfaceStyle), `expo-system-ui: Invalid userInterfaceStyle: "${userInterfaceStyle}"`);
|
|
23
|
+
return { userInterfaceStyle };
|
|
24
|
+
}
|
|
25
|
+
function setStrings(strings, { userInterfaceStyle }) {
|
|
26
|
+
const pairs = [[USER_INTERFACE_STYLE_KEY, userInterfaceStyle]];
|
|
27
|
+
const stringItems = [];
|
|
28
|
+
for (const [key, value] of pairs) {
|
|
29
|
+
if (value == null) {
|
|
30
|
+
// Since we're using custom strings, we can remove them for convenience between prebuilds.
|
|
31
|
+
strings = config_plugins_1.AndroidConfig.Strings.removeStringItem(key, strings);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
stringItems.push(config_plugins_1.AndroidConfig.Resources.buildResourceItem({
|
|
35
|
+
name: key,
|
|
36
|
+
value: String(value),
|
|
37
|
+
translatable: false,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return config_plugins_1.AndroidConfig.Strings.setStringItem(stringItems, strings);
|
|
42
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExpoConfig } from 'expo/config';
|
|
2
|
+
import { ConfigPlugin, InfoPlist } from 'expo/config-plugins';
|
|
3
|
+
export declare const withIosRootViewBackgroundColor: ConfigPlugin;
|
|
4
|
+
export declare function setRootViewBackgroundColor(config: Pick<ExpoConfig, 'backgroundColor' | 'ios'>, infoPlist: InfoPlist): InfoPlist;
|
|
5
|
+
export declare function getRootViewBackgroundColor(config: Pick<ExpoConfig, 'ios' | 'backgroundColor'>): string | null;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withIosRootViewBackgroundColor = void 0;
|
|
7
|
+
exports.setRootViewBackgroundColor = setRootViewBackgroundColor;
|
|
8
|
+
exports.getRootViewBackgroundColor = getRootViewBackgroundColor;
|
|
9
|
+
// @ts-ignore: uses flow
|
|
10
|
+
const normalize_color_1 = __importDefault(require("@react-native/normalize-color"));
|
|
11
|
+
const config_plugins_1 = require("expo/config-plugins");
|
|
12
|
+
// Maps to the template AppDelegate.m
|
|
13
|
+
const BACKGROUND_COLOR_KEY = 'RCTRootViewBackgroundColor';
|
|
14
|
+
const debug = require('debug')('expo:system-ui:plugin:ios');
|
|
15
|
+
const withIosRootViewBackgroundColor = (config) => {
|
|
16
|
+
config = (0, config_plugins_1.withInfoPlist)(config, (config) => {
|
|
17
|
+
config.modResults = setRootViewBackgroundColor(config, config.modResults);
|
|
18
|
+
return config;
|
|
19
|
+
});
|
|
20
|
+
return config;
|
|
21
|
+
};
|
|
22
|
+
exports.withIosRootViewBackgroundColor = withIosRootViewBackgroundColor;
|
|
23
|
+
function setRootViewBackgroundColor(config, infoPlist) {
|
|
24
|
+
const backgroundColor = getRootViewBackgroundColor(config);
|
|
25
|
+
if (!backgroundColor) {
|
|
26
|
+
delete infoPlist[BACKGROUND_COLOR_KEY];
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
let color = (0, normalize_color_1.default)(backgroundColor);
|
|
30
|
+
if (!color) {
|
|
31
|
+
throw new Error('Invalid background color on iOS');
|
|
32
|
+
}
|
|
33
|
+
color = ((color << 24) | (color >>> 8)) >>> 0;
|
|
34
|
+
infoPlist[BACKGROUND_COLOR_KEY] = color;
|
|
35
|
+
debug(`Convert color: ${backgroundColor} -> ${color}`);
|
|
36
|
+
}
|
|
37
|
+
return infoPlist;
|
|
38
|
+
}
|
|
39
|
+
function getRootViewBackgroundColor(config) {
|
|
40
|
+
return config.ios?.backgroundColor || config.backgroundColor || null;
|
|
41
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExpoConfig } from 'expo/config';
|
|
2
|
+
import { InfoPlist, ConfigPlugin } from 'expo/config-plugins';
|
|
3
|
+
export declare const withIosUserInterfaceStyle: ConfigPlugin;
|
|
4
|
+
export declare function getUserInterfaceStyle(config: Pick<ExpoConfig, 'ios' | 'userInterfaceStyle'>): string;
|
|
5
|
+
export declare function setUserInterfaceStyle(config: Pick<ExpoConfig, 'ios' | 'userInterfaceStyle'>, { UIUserInterfaceStyle, ...infoPlist }: InfoPlist): InfoPlist;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withIosUserInterfaceStyle = void 0;
|
|
4
|
+
exports.getUserInterfaceStyle = getUserInterfaceStyle;
|
|
5
|
+
exports.setUserInterfaceStyle = setUserInterfaceStyle;
|
|
6
|
+
const config_plugins_1 = require("expo/config-plugins");
|
|
7
|
+
const withIosUserInterfaceStyle = (config) => {
|
|
8
|
+
return (0, config_plugins_1.withInfoPlist)(config, (config) => {
|
|
9
|
+
config.modResults = setUserInterfaceStyle(config, config.modResults);
|
|
10
|
+
return config;
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.withIosUserInterfaceStyle = withIosUserInterfaceStyle;
|
|
14
|
+
function getUserInterfaceStyle(config) {
|
|
15
|
+
return config.ios?.userInterfaceStyle ?? config.userInterfaceStyle ?? 'light';
|
|
16
|
+
}
|
|
17
|
+
function setUserInterfaceStyle(config, { UIUserInterfaceStyle, ...infoPlist }) {
|
|
18
|
+
const userInterfaceStyle = getUserInterfaceStyle(config);
|
|
19
|
+
const style = mapUserInterfaceStyleForInfoPlist(userInterfaceStyle);
|
|
20
|
+
if (!style) {
|
|
21
|
+
return infoPlist;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
...infoPlist,
|
|
25
|
+
UIUserInterfaceStyle: style,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function mapUserInterfaceStyleForInfoPlist(userInterfaceStyle) {
|
|
29
|
+
switch (userInterfaceStyle) {
|
|
30
|
+
case 'light':
|
|
31
|
+
return 'Light';
|
|
32
|
+
case 'dark':
|
|
33
|
+
return 'Dark';
|
|
34
|
+
case 'automatic':
|
|
35
|
+
return 'Automatic';
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_plugins_1 = require("expo/config-plugins");
|
|
4
|
+
const withAndroidRootViewBackgroundColor_1 = require("./withAndroidRootViewBackgroundColor");
|
|
5
|
+
const withAndroidUserInterfaceStyle_1 = require("./withAndroidUserInterfaceStyle");
|
|
6
|
+
const withIosRootViewBackgroundColor_1 = require("./withIosRootViewBackgroundColor");
|
|
7
|
+
const withIosUserInterfaceStyle_1 = require("./withIosUserInterfaceStyle");
|
|
8
|
+
const pkg = require('expo-system-ui/package.json');
|
|
9
|
+
const withSystemUI = (config) => {
|
|
10
|
+
return (0, config_plugins_1.withPlugins)(config, [
|
|
11
|
+
withAndroidRootViewBackgroundColor_1.withAndroidRootViewBackgroundColor,
|
|
12
|
+
withIosRootViewBackgroundColor_1.withIosRootViewBackgroundColor,
|
|
13
|
+
withAndroidUserInterfaceStyle_1.withAndroidUserInterfaceStyle,
|
|
14
|
+
withIosUserInterfaceStyle_1.withIosUserInterfaceStyle,
|
|
15
|
+
]);
|
|
16
|
+
};
|
|
17
|
+
exports.default = (0, config_plugins_1.createRunOncePlugin)(withSystemUI, pkg.name, pkg.version);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ExpoConfig } from 'expo/config';
|
|
2
|
+
import {
|
|
3
|
+
AndroidConfig,
|
|
4
|
+
ConfigPlugin,
|
|
5
|
+
withAndroidColors,
|
|
6
|
+
withAndroidStyles,
|
|
7
|
+
} from 'expo/config-plugins';
|
|
8
|
+
|
|
9
|
+
const { assignColorValue } = AndroidConfig.Colors;
|
|
10
|
+
const { assignStylesValue, getAppThemeLightNoActionBarGroup } = AndroidConfig.Styles;
|
|
11
|
+
|
|
12
|
+
const ANDROID_WINDOW_BACKGROUND = 'android:windowBackground';
|
|
13
|
+
const WINDOW_BACKGROUND_COLOR = 'activityBackground';
|
|
14
|
+
|
|
15
|
+
export const withAndroidRootViewBackgroundColor: ConfigPlugin = (config) => {
|
|
16
|
+
config = withRootViewBackgroundColorColors(config);
|
|
17
|
+
config = withRootViewBackgroundColorStyles(config);
|
|
18
|
+
return config;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const withRootViewBackgroundColorColors: ConfigPlugin = (config) => {
|
|
22
|
+
return withAndroidColors(config, async (config) => {
|
|
23
|
+
config.modResults = assignColorValue(config.modResults, {
|
|
24
|
+
value: getRootViewBackgroundColor(config),
|
|
25
|
+
name: WINDOW_BACKGROUND_COLOR,
|
|
26
|
+
});
|
|
27
|
+
return config;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const withRootViewBackgroundColorStyles: ConfigPlugin = (config) => {
|
|
32
|
+
return withAndroidStyles(config, async (config) => {
|
|
33
|
+
config.modResults = assignStylesValue(config.modResults, {
|
|
34
|
+
add: !!getRootViewBackgroundColor(config),
|
|
35
|
+
parent: getAppThemeLightNoActionBarGroup(),
|
|
36
|
+
name: ANDROID_WINDOW_BACKGROUND,
|
|
37
|
+
value: `@color/${WINDOW_BACKGROUND_COLOR}`,
|
|
38
|
+
});
|
|
39
|
+
return config;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function getRootViewBackgroundColor(
|
|
44
|
+
config: Pick<ExpoConfig, 'android' | 'backgroundColor'>
|
|
45
|
+
) {
|
|
46
|
+
return config.android?.backgroundColor || config.backgroundColor || null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { ExpoConfig } from 'expo/config';
|
|
3
|
+
import { AndroidConfig, ConfigPlugin, withStringsXml } from 'expo/config-plugins';
|
|
4
|
+
|
|
5
|
+
export type Props = {
|
|
6
|
+
userInterfaceStyle?: ExpoConfig['userInterfaceStyle'];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// strings.xml keys, this should not change.
|
|
10
|
+
const USER_INTERFACE_STYLE_KEY = 'expo_system_ui_user_interface_style';
|
|
11
|
+
|
|
12
|
+
export const withAndroidUserInterfaceStyle: ConfigPlugin<void> = (config) => {
|
|
13
|
+
return withStringsXml(config, (config) => {
|
|
14
|
+
config.modResults = setStrings(config.modResults, resolveProps(config));
|
|
15
|
+
return config;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function resolveProps(config: Pick<ExpoConfig, 'userInterfaceStyle' | 'android'>): Props {
|
|
20
|
+
const userInterfaceStyle = config.android?.userInterfaceStyle ?? config.userInterfaceStyle;
|
|
21
|
+
|
|
22
|
+
assert(
|
|
23
|
+
!userInterfaceStyle || ['automatic', 'light', 'dark'].includes(userInterfaceStyle),
|
|
24
|
+
`expo-system-ui: Invalid userInterfaceStyle: "${userInterfaceStyle}"`
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return { userInterfaceStyle };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function setStrings(
|
|
31
|
+
strings: AndroidConfig.Resources.ResourceXML,
|
|
32
|
+
{ userInterfaceStyle }: Props
|
|
33
|
+
): AndroidConfig.Resources.ResourceXML {
|
|
34
|
+
const pairs = [[USER_INTERFACE_STYLE_KEY, userInterfaceStyle]] as [string, any][];
|
|
35
|
+
|
|
36
|
+
const stringItems: AndroidConfig.Resources.ResourceItemXML[] = [];
|
|
37
|
+
for (const [key, value] of pairs) {
|
|
38
|
+
if (value == null) {
|
|
39
|
+
// Since we're using custom strings, we can remove them for convenience between prebuilds.
|
|
40
|
+
strings = AndroidConfig.Strings.removeStringItem(key, strings);
|
|
41
|
+
} else {
|
|
42
|
+
stringItems.push(
|
|
43
|
+
AndroidConfig.Resources.buildResourceItem({
|
|
44
|
+
name: key,
|
|
45
|
+
value: String(value),
|
|
46
|
+
translatable: false,
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return AndroidConfig.Strings.setStringItem(stringItems, strings);
|
|
53
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// @ts-ignore: uses flow
|
|
2
|
+
import normalizeColor from '@react-native/normalize-color';
|
|
3
|
+
import { ExpoConfig } from 'expo/config';
|
|
4
|
+
import { ConfigPlugin, InfoPlist, withInfoPlist } from 'expo/config-plugins';
|
|
5
|
+
|
|
6
|
+
// Maps to the template AppDelegate.m
|
|
7
|
+
const BACKGROUND_COLOR_KEY = 'RCTRootViewBackgroundColor';
|
|
8
|
+
|
|
9
|
+
const debug = require('debug')('expo:system-ui:plugin:ios');
|
|
10
|
+
|
|
11
|
+
export const withIosRootViewBackgroundColor: ConfigPlugin = (config) => {
|
|
12
|
+
config = withInfoPlist(config, (config) => {
|
|
13
|
+
config.modResults = setRootViewBackgroundColor(config, config.modResults);
|
|
14
|
+
return config;
|
|
15
|
+
});
|
|
16
|
+
return config;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function setRootViewBackgroundColor(
|
|
20
|
+
config: Pick<ExpoConfig, 'backgroundColor' | 'ios'>,
|
|
21
|
+
infoPlist: InfoPlist
|
|
22
|
+
): InfoPlist {
|
|
23
|
+
const backgroundColor = getRootViewBackgroundColor(config);
|
|
24
|
+
if (!backgroundColor) {
|
|
25
|
+
delete infoPlist[BACKGROUND_COLOR_KEY];
|
|
26
|
+
} else {
|
|
27
|
+
let color = normalizeColor(backgroundColor);
|
|
28
|
+
if (!color) {
|
|
29
|
+
throw new Error('Invalid background color on iOS');
|
|
30
|
+
}
|
|
31
|
+
color = ((color << 24) | (color >>> 8)) >>> 0;
|
|
32
|
+
infoPlist[BACKGROUND_COLOR_KEY] = color;
|
|
33
|
+
|
|
34
|
+
debug(`Convert color: ${backgroundColor} -> ${color}`);
|
|
35
|
+
}
|
|
36
|
+
return infoPlist;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getRootViewBackgroundColor(config: Pick<ExpoConfig, 'ios' | 'backgroundColor'>) {
|
|
40
|
+
return config.ios?.backgroundColor || config.backgroundColor || null;
|
|
41
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ExpoConfig } from 'expo/config';
|
|
2
|
+
import { InfoPlist, ConfigPlugin, withInfoPlist } from 'expo/config-plugins';
|
|
3
|
+
|
|
4
|
+
export const withIosUserInterfaceStyle: ConfigPlugin = (config) => {
|
|
5
|
+
return withInfoPlist(config, (config) => {
|
|
6
|
+
config.modResults = setUserInterfaceStyle(config, config.modResults);
|
|
7
|
+
return config;
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function getUserInterfaceStyle(
|
|
12
|
+
config: Pick<ExpoConfig, 'ios' | 'userInterfaceStyle'>
|
|
13
|
+
): string {
|
|
14
|
+
return config.ios?.userInterfaceStyle ?? config.userInterfaceStyle ?? 'light';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function setUserInterfaceStyle(
|
|
18
|
+
config: Pick<ExpoConfig, 'ios' | 'userInterfaceStyle'>,
|
|
19
|
+
{ UIUserInterfaceStyle, ...infoPlist }: InfoPlist
|
|
20
|
+
): InfoPlist {
|
|
21
|
+
const userInterfaceStyle = getUserInterfaceStyle(config);
|
|
22
|
+
const style = mapUserInterfaceStyleForInfoPlist(userInterfaceStyle);
|
|
23
|
+
|
|
24
|
+
if (!style) {
|
|
25
|
+
return infoPlist;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
...infoPlist,
|
|
30
|
+
UIUserInterfaceStyle: style,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function mapUserInterfaceStyleForInfoPlist(
|
|
35
|
+
userInterfaceStyle: string
|
|
36
|
+
): NonNullable<InfoPlist['UIUserInterfaceStyle']> | null {
|
|
37
|
+
switch (userInterfaceStyle) {
|
|
38
|
+
case 'light':
|
|
39
|
+
return 'Light';
|
|
40
|
+
case 'dark':
|
|
41
|
+
return 'Dark';
|
|
42
|
+
case 'automatic':
|
|
43
|
+
return 'Automatic';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConfigPlugin, createRunOncePlugin, withPlugins } from 'expo/config-plugins';
|
|
2
|
+
|
|
3
|
+
import { withAndroidRootViewBackgroundColor } from './withAndroidRootViewBackgroundColor';
|
|
4
|
+
import { withAndroidUserInterfaceStyle } from './withAndroidUserInterfaceStyle';
|
|
5
|
+
import { withIosRootViewBackgroundColor } from './withIosRootViewBackgroundColor';
|
|
6
|
+
import { withIosUserInterfaceStyle } from './withIosUserInterfaceStyle';
|
|
7
|
+
|
|
8
|
+
const pkg = require('expo-system-ui/package.json');
|
|
9
|
+
|
|
10
|
+
const withSystemUI: ConfigPlugin = (config) => {
|
|
11
|
+
return withPlugins(config, [
|
|
12
|
+
withAndroidRootViewBackgroundColor,
|
|
13
|
+
withIosRootViewBackgroundColor,
|
|
14
|
+
withAndroidUserInterfaceStyle,
|
|
15
|
+
withIosUserInterfaceStyle,
|
|
16
|
+
]);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default createRunOncePlugin(withSystemUI, pkg.name, pkg.version);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/withAndroidRootViewBackgroundColor.ts","./src/withAndroidUserInterfaceStyle.ts","./src/withIosRootViewBackgroundColor.ts","./src/withIosUserInterfaceStyle.ts","./src/withSystemUI.ts"],"version":"5.7.2"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
dependencies: {
|
|
3
|
+
'@amazon-devices/react-native-kepler': {
|
|
4
|
+
platforms: {
|
|
5
|
+
kepler: null, // do not use platform definition from @react-native-kepler
|
|
6
|
+
},
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
dependency: {
|
|
10
|
+
platforms: {
|
|
11
|
+
kepler: {
|
|
12
|
+
autolink: {
|
|
13
|
+
ExpoSystemUILib: {
|
|
14
|
+
provider: 'system',
|
|
15
|
+
turbomodules: ['ExpoSystemUI'],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { KeplerTurboModule, TurboModuleRegistry } from '@amazon-devices/keplerscript-turbomodule-api';
|
|
2
|
+
|
|
3
|
+
interface Spec extends KeplerTurboModule {
|
|
4
|
+
readonly getBackgroundColorAsync: () => Promise<string>;
|
|
5
|
+
readonly resetBackgroundColorAsync: () => Promise<void>;
|
|
6
|
+
readonly setBackgroundColorAsync: (color: number) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const nativeModule = TurboModuleRegistry.getEnforcing<Spec>('ExpoSystemUI') as Spec;
|
|
10
|
+
|
|
11
|
+
interface KeplerSystemUI {
|
|
12
|
+
readonly getBackgroundColorAsync: () => Promise<string | null>;
|
|
13
|
+
readonly setBackgroundColorAsync: (color: number | null) => Promise<void | null>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const module: KeplerSystemUI = {
|
|
17
|
+
async getBackgroundColorAsync() {
|
|
18
|
+
return nativeModule.getBackgroundColorAsync();
|
|
19
|
+
},
|
|
20
|
+
async setBackgroundColorAsync(color: number | null) {
|
|
21
|
+
return color
|
|
22
|
+
? nativeModule.setBackgroundColorAsync(color)
|
|
23
|
+
: nativeModule.resetBackgroundColorAsync();
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default module;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Platform } from 'expo-modules-core';
|
|
2
|
+
// @ts-ignore: untyped
|
|
3
|
+
import normalizeColor from 'react-native-web/dist/cjs/modules/normalizeColor';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
get name(): string {
|
|
7
|
+
return 'ExpoSystemUI';
|
|
8
|
+
},
|
|
9
|
+
getBackgroundColorAsync() {
|
|
10
|
+
if (Platform.isDOMAvailable) {
|
|
11
|
+
return normalizeColor(document.body.style.backgroundColor);
|
|
12
|
+
} else {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
setBackgroundColorAsync(color: string | null) {
|
|
17
|
+
if (Platform.isDOMAvailable) {
|
|
18
|
+
document.body.style.backgroundColor = color ?? 'white';
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
};
|
package/src/SystemUI.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ColorValue, Platform, processColor } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import ExpoSystemUI from './ExpoSystemUI';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Changes the root view background color.
|
|
7
|
+
* Call this function in the root file outside of you component.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* SystemUI.setBackgroundColorAsync("black");
|
|
12
|
+
* ```
|
|
13
|
+
* @param color Any valid [CSS 3 (SVG) color](http://www.w3.org/TR/css3-color/#svg-color).
|
|
14
|
+
*/
|
|
15
|
+
export async function setBackgroundColorAsync(color: ColorValue | null): Promise<void> {
|
|
16
|
+
if (color == null) {
|
|
17
|
+
return await ExpoSystemUI.setBackgroundColorAsync(null);
|
|
18
|
+
} else {
|
|
19
|
+
const colorNumber = Platform.OS === 'web' ? color : processColor(color);
|
|
20
|
+
return await ExpoSystemUI.setBackgroundColorAsync(colorNumber);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Gets the root view background color.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const color = await SystemUI.getBackgroundColorAsync();
|
|
30
|
+
* ```
|
|
31
|
+
* @returns Current root view background color in hex format. Returns `null` if the background color is not set.
|
|
32
|
+
*/
|
|
33
|
+
export async function getBackgroundColorAsync(): Promise<ColorValue | null> {
|
|
34
|
+
return await ExpoSystemUI.getBackgroundColorAsync();
|
|
35
|
+
}
|