@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 @@
|
|
|
1
|
+
{"version":3,"file":"ExpoSystemUI.web.js","sourceRoot":"","sources":["../src/ExpoSystemUI.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,sBAAsB;AACtB,OAAO,cAAc,MAAM,kDAAkD,CAAC;AAE9E,eAAe;IACb,IAAI,IAAI;QACN,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,uBAAuB;QACrB,IAAI,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC5B,OAAO,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAC7D,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,uBAAuB,CAAC,KAAoB;QAC1C,IAAI,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC5B,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,KAAK,IAAI,OAAO,CAAC;QACzD,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import { Platform } from 'expo-modules-core';\n// @ts-ignore: untyped\nimport normalizeColor from 'react-native-web/dist/cjs/modules/normalizeColor';\n\nexport default {\n get name(): string {\n return 'ExpoSystemUI';\n },\n getBackgroundColorAsync() {\n if (Platform.isDOMAvailable) {\n return normalizeColor(document.body.style.backgroundColor);\n } else {\n return null;\n }\n },\n setBackgroundColorAsync(color: string | null) {\n if (Platform.isDOMAvailable) {\n document.body.style.backgroundColor = color ?? 'white';\n }\n },\n};\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ColorValue } from 'react-native';
|
|
2
|
+
/**
|
|
3
|
+
* Changes the root view background color.
|
|
4
|
+
* Call this function in the root file outside of you component.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* SystemUI.setBackgroundColorAsync("black");
|
|
9
|
+
* ```
|
|
10
|
+
* @param color Any valid [CSS 3 (SVG) color](http://www.w3.org/TR/css3-color/#svg-color).
|
|
11
|
+
*/
|
|
12
|
+
export declare function setBackgroundColorAsync(color: ColorValue | null): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the root view background color.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const color = await SystemUI.getBackgroundColorAsync();
|
|
19
|
+
* ```
|
|
20
|
+
* @returns Current root view background color in hex format. Returns `null` if the background color is not set.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getBackgroundColorAsync(): Promise<ColorValue | null>;
|
|
23
|
+
//# sourceMappingURL=SystemUI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemUI.d.ts","sourceRoot":"","sources":["../src/SystemUI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AAIlE;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAOrF;AAED;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAE1E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Platform, processColor } from 'react-native';
|
|
2
|
+
import ExpoSystemUI from './ExpoSystemUI';
|
|
3
|
+
/**
|
|
4
|
+
* Changes the root view background color.
|
|
5
|
+
* Call this function in the root file outside of you component.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* SystemUI.setBackgroundColorAsync("black");
|
|
10
|
+
* ```
|
|
11
|
+
* @param color Any valid [CSS 3 (SVG) color](http://www.w3.org/TR/css3-color/#svg-color).
|
|
12
|
+
*/
|
|
13
|
+
export async function setBackgroundColorAsync(color) {
|
|
14
|
+
if (color == null) {
|
|
15
|
+
return await ExpoSystemUI.setBackgroundColorAsync(null);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const colorNumber = Platform.OS === 'web' ? color : processColor(color);
|
|
19
|
+
return await ExpoSystemUI.setBackgroundColorAsync(colorNumber);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets the root view background color.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const color = await SystemUI.getBackgroundColorAsync();
|
|
28
|
+
* ```
|
|
29
|
+
* @returns Current root view background color in hex format. Returns `null` if the background color is not set.
|
|
30
|
+
*/
|
|
31
|
+
export async function getBackgroundColorAsync() {
|
|
32
|
+
return await ExpoSystemUI.getBackgroundColorAsync();
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=SystemUI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemUI.js","sourceRoot":"","sources":["../src/SystemUI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAElE,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,KAAwB;IACpE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,MAAM,YAAY,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC;SAAM,CAAC;QACN,MAAM,WAAW,GAAG,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACxE,OAAO,MAAM,YAAY,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,OAAO,MAAM,YAAY,CAAC,uBAAuB,EAAE,CAAC;AACtD,CAAC","sourcesContent":["import { ColorValue, Platform, processColor } from 'react-native';\n\nimport ExpoSystemUI from './ExpoSystemUI';\n\n/**\n * Changes the root view background color.\n * Call this function in the root file outside of you component.\n *\n * @example\n * ```ts\n * SystemUI.setBackgroundColorAsync(\"black\");\n * ```\n * @param color Any valid [CSS 3 (SVG) color](http://www.w3.org/TR/css3-color/#svg-color).\n */\nexport async function setBackgroundColorAsync(color: ColorValue | null): Promise<void> {\n if (color == null) {\n return await ExpoSystemUI.setBackgroundColorAsync(null);\n } else {\n const colorNumber = Platform.OS === 'web' ? color : processColor(color);\n return await ExpoSystemUI.setBackgroundColorAsync(colorNumber);\n }\n}\n\n/**\n * Gets the root view background color.\n *\n * @example\n * ```ts\n * const color = await SystemUI.getBackgroundColorAsync();\n * ```\n * @returns Current root view background color in hex format. Returns `null` if the background color is not set.\n */\nexport async function getBackgroundColorAsync(): Promise<ColorValue | null> {\n return await ExpoSystemUI.getBackgroundColorAsync();\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Copyright 2021-present 650 Industries. (AKA Expo) All rights reserved.
|
|
2
|
+
|
|
3
|
+
import ExpoModulesCore
|
|
4
|
+
|
|
5
|
+
public class ExpoSystemUIModule: Module {
|
|
6
|
+
private static let colorKey = "ExpoSystemUI.backgroundColor"
|
|
7
|
+
public func definition() -> ModuleDefinition {
|
|
8
|
+
Name("ExpoSystemUI")
|
|
9
|
+
|
|
10
|
+
OnCreate {
|
|
11
|
+
// TODO: Maybe read from the app manifest instead of from Info.plist.
|
|
12
|
+
// Set / reset the initial color on reload and app start.
|
|
13
|
+
let color = UserDefaults.standard.integer(forKey: Self.colorKey)
|
|
14
|
+
|
|
15
|
+
if color > 0 {
|
|
16
|
+
Self.setBackgroundColorAsync(color: color)
|
|
17
|
+
} else {
|
|
18
|
+
Self.setBackgroundColorAsync(color: nil)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
AsyncFunction("getBackgroundColorAsync") { () -> String? in
|
|
23
|
+
Self.getBackgroundColor()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
AsyncFunction("setBackgroundColorAsync") { (color: Int?) in
|
|
27
|
+
Self.setBackgroundColorAsync(color: color)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static func getBackgroundColor() -> String? {
|
|
32
|
+
var color: String?
|
|
33
|
+
EXUtilities.performSynchronously {
|
|
34
|
+
// Get the root view controller of the delegate window.
|
|
35
|
+
if let window = UIApplication.shared.delegate?.window, let backgroundColor = window?.rootViewController?.view.backgroundColor?.cgColor {
|
|
36
|
+
color = EXUtilities.hexString(with: backgroundColor)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return color
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static func setBackgroundColorAsync(color: Int?) {
|
|
43
|
+
EXUtilities.performSynchronously {
|
|
44
|
+
if color == nil {
|
|
45
|
+
if let window = UIApplication.shared.delegate?.window {
|
|
46
|
+
UserDefaults.standard.removeObject(forKey: colorKey)
|
|
47
|
+
let interfaceStyle = window?.traitCollection.userInterfaceStyle
|
|
48
|
+
window?.backgroundColor = nil
|
|
49
|
+
|
|
50
|
+
switch interfaceStyle {
|
|
51
|
+
case .dark:
|
|
52
|
+
window?.rootViewController?.view.backgroundColor = .black
|
|
53
|
+
case .light:
|
|
54
|
+
window?.rootViewController?.view.backgroundColor = .white
|
|
55
|
+
default:
|
|
56
|
+
window?.rootViewController?.view.backgroundColor = .white
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
UserDefaults.standard.set(color, forKey: colorKey)
|
|
62
|
+
let backgroundColor = EXUtilities.uiColor(color)
|
|
63
|
+
// Set the app-wide window, this could have future issues when running multiple React apps,
|
|
64
|
+
// i.e. dev client can't use expo-system-ui.
|
|
65
|
+
// Without setting the window backgroundColor, native-stack modals will show the wrong color.
|
|
66
|
+
if let window = UIApplication.shared.delegate?.window {
|
|
67
|
+
window?.backgroundColor = backgroundColor
|
|
68
|
+
window?.rootViewController?.view.backgroundColor = backgroundColor
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'ExpoSystemUI'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = package['description']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platform = :ios, '13.0'
|
|
14
|
+
s.swift_version = '5.4'
|
|
15
|
+
s.source = { git: 'https://github.com/expo/expo.git' }
|
|
16
|
+
s.static_framework = true
|
|
17
|
+
|
|
18
|
+
s.dependency 'ExpoModulesCore'
|
|
19
|
+
|
|
20
|
+
# Swift/Objective-C compatibility
|
|
21
|
+
s.pod_target_xcconfig = {
|
|
22
|
+
'DEFINES_MODULE' => 'YES'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
|
|
26
|
+
s.source_files = "#{s.name}/**/*.h"
|
|
27
|
+
s.vendored_frameworks = "#{s.name}.xcframework"
|
|
28
|
+
else
|
|
29
|
+
s.source_files = "#{s.name}/**/*.{h,m,swift}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include "ExpoSystemUI.h"
|
|
10
|
+
|
|
11
|
+
#include <KeplerScript/logger/KPLog.h>
|
|
12
|
+
#include <Volta/graphics/Color.h>
|
|
13
|
+
|
|
14
|
+
ExpoSystemUI::ExpoSystemUI(volta::react::IKeplerUIManager& uiManager) : syncDelegate(uiManager) {}
|
|
15
|
+
|
|
16
|
+
volta::react::Promise ExpoSystemUI::getBackgroundColorAsync() {
|
|
17
|
+
return volta::react::Promise([this](std::shared_ptr<volta::react::Promise> promise) {
|
|
18
|
+
try {
|
|
19
|
+
auto rgbColorStr = syncDelegate.getBackgroundColor();
|
|
20
|
+
promise->resolve(rgbColorStr);
|
|
21
|
+
} catch (std::exception& e) {
|
|
22
|
+
promise->reject(std::string{"getBackgroundColorAsync error: " + std::string(e.what())});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
volta::react::Promise ExpoSystemUI::resetBackgroundColorAsync() {
|
|
28
|
+
return volta::react::Promise([this](std::shared_ptr<volta::react::Promise> promise) {
|
|
29
|
+
try {
|
|
30
|
+
syncDelegate.resetBackgroundColor();
|
|
31
|
+
promise->resolve();
|
|
32
|
+
} catch (std::exception& e) {
|
|
33
|
+
promise->reject(std::string{"resetBackgroundColorAsync error: " + std::string(e.what())});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
volta::react::Promise ExpoSystemUI::setBackgroundColorAsync(int64_t color) {
|
|
39
|
+
return volta::react::Promise([this, color](std::shared_ptr<volta::react::Promise> promise) {
|
|
40
|
+
try {
|
|
41
|
+
syncDelegate.setBackgroundColor(color);
|
|
42
|
+
promise->resolve();
|
|
43
|
+
} catch (std::exception& e) {
|
|
44
|
+
promise->reject(std::string{"setBackgroundColorAsync error: " + std::string(e.what())});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <KeplerScript/components/KeplerViewComponent.h>
|
|
10
|
+
#include <KeplerScript/modules/KeplerTurboModule.h>
|
|
11
|
+
#include <Volta/graphics/Color.h>
|
|
12
|
+
|
|
13
|
+
#include "ExpoSystemUIImpl.h"
|
|
14
|
+
#include "IKeplerUIManager.h"
|
|
15
|
+
|
|
16
|
+
class KEPLERSCRIPT_EXPORT ExpoSystemUI {
|
|
17
|
+
public:
|
|
18
|
+
explicit ExpoSystemUI(volta::react::IKeplerUIManager&);
|
|
19
|
+
|
|
20
|
+
volta::react::Promise getBackgroundColorAsync();
|
|
21
|
+
volta::react::Promise resetBackgroundColorAsync();
|
|
22
|
+
volta::react::Promise setBackgroundColorAsync(int64_t color);
|
|
23
|
+
|
|
24
|
+
private:
|
|
25
|
+
#ifdef UNIT_TEST
|
|
26
|
+
public:
|
|
27
|
+
#endif
|
|
28
|
+
ExpoSystemUIImpl syncDelegate;
|
|
29
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include "ExpoSystemUIImpl.h"
|
|
10
|
+
|
|
11
|
+
#include <KeplerScript/logger/KPLog.h>
|
|
12
|
+
#include <Volta/graphics/Color.h>
|
|
13
|
+
|
|
14
|
+
#include <iomanip>
|
|
15
|
+
#include <sstream>
|
|
16
|
+
|
|
17
|
+
ExpoSystemUIImpl::ExpoSystemUIImpl(volta::react::IKeplerUIManager& uiManager) {
|
|
18
|
+
view = uiManager.getComponentViewByTag(1);
|
|
19
|
+
if (view == nullptr) {
|
|
20
|
+
throw std::runtime_error("Failing getting view instance (view can't be nullptr)");
|
|
21
|
+
}
|
|
22
|
+
systemBackgroundColor = view->getBackgroundColor();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
std::string ExpoSystemUIImpl::getBackgroundColor() {
|
|
26
|
+
volta::graphics::Color color = view->getBackgroundColor();
|
|
27
|
+
std::ostringstream rgbColor;
|
|
28
|
+
rgbColor << "#" << std::setfill('0') << std::hex << std::setw(2) << color.r() << std::setw(2) << color.g()
|
|
29
|
+
<< std::setw(2) << color.b();
|
|
30
|
+
return rgbColor.str();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void ExpoSystemUIImpl::resetBackgroundColor() {
|
|
34
|
+
view->setBackgroundColor(systemBackgroundColor.argb());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void ExpoSystemUIImpl::setBackgroundColor(int64_t color) {
|
|
38
|
+
view->setBackgroundColor(color);
|
|
39
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <KeplerScript/components/KeplerViewComponent.h>
|
|
10
|
+
#include <KeplerScript/modules/KeplerTurboModule.h>
|
|
11
|
+
#include <Volta/graphics/Color.h>
|
|
12
|
+
|
|
13
|
+
#include "IKeplerUIManager.h"
|
|
14
|
+
|
|
15
|
+
class KEPLERSCRIPT_EXPORT ExpoSystemUIImpl {
|
|
16
|
+
public:
|
|
17
|
+
explicit ExpoSystemUIImpl(volta::react::IKeplerUIManager&);
|
|
18
|
+
|
|
19
|
+
std::string getBackgroundColor();
|
|
20
|
+
void resetBackgroundColor();
|
|
21
|
+
void setBackgroundColor(int64_t color);
|
|
22
|
+
|
|
23
|
+
private:
|
|
24
|
+
#ifdef UNIT_TEST
|
|
25
|
+
public:
|
|
26
|
+
#endif
|
|
27
|
+
std::shared_ptr<volta::react::KeplerViewComponent> view;
|
|
28
|
+
volta::graphics::Color systemBackgroundColor{0, 0, 0, 0};
|
|
29
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include "ExpoSystemUITurboModule.h"
|
|
10
|
+
|
|
11
|
+
#include <KeplerScript/logger/KPLog.h>
|
|
12
|
+
#include <Volta/graphics/Color.h>
|
|
13
|
+
|
|
14
|
+
#include <memory>
|
|
15
|
+
|
|
16
|
+
#include "ExpoUIManager.h"
|
|
17
|
+
|
|
18
|
+
ExpoSystemUITurboModule::ExpoSystemUITurboModule() : volta::react::KeplerTurboModule("ExpoSystemUI") {
|
|
19
|
+
volta::react::KPLog.debug("ExpoSystemUI constructor {}", name());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void ExpoSystemUITurboModule::aggregateMethods(
|
|
23
|
+
volta::react::MethodAggregator<volta::react::KeplerTurboModule>& methodAggregator) const noexcept {
|
|
24
|
+
volta::react::KPLog.debug("ExpoSystemUITurboModule::aggregateMethods");
|
|
25
|
+
|
|
26
|
+
methodAggregator.addMethod("getBackgroundColorAsync", 0, &ExpoSystemUITurboModule::getBackgroundColorAsync);
|
|
27
|
+
methodAggregator.addMethod("resetBackgroundColorAsync", 0, &ExpoSystemUITurboModule::resetBackgroundColorAsync);
|
|
28
|
+
methodAggregator.addMethod("setBackgroundColorAsync", 1, &ExpoSystemUITurboModule::setBackgroundColorAsync);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
volta::react::Promise ExpoSystemUITurboModule::getBackgroundColorAsync() {
|
|
32
|
+
volta::react::KPLog.debug("ExpoSystemUI::getBackgroundColorAsync");
|
|
33
|
+
ensureSystemUIInitialized();
|
|
34
|
+
return lazyDelegate->getBackgroundColorAsync();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
volta::react::Promise ExpoSystemUITurboModule::resetBackgroundColorAsync() {
|
|
38
|
+
volta::react::KPLog.debug("ExpoSystemUI::resetBackgroundColorAsync");
|
|
39
|
+
ensureSystemUIInitialized();
|
|
40
|
+
return lazyDelegate->resetBackgroundColorAsync();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
volta::react::Promise ExpoSystemUITurboModule::setBackgroundColorAsync(int64_t color) {
|
|
44
|
+
volta::react::KPLog.debug("ExpoSystemUI::setBackgroundColorAsync, color {}", color);
|
|
45
|
+
ensureSystemUIInitialized();
|
|
46
|
+
return lazyDelegate->setBackgroundColorAsync(color);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void ExpoSystemUITurboModule::ensureSystemUIInitialized() {
|
|
50
|
+
volta::react::KPLog.debug("ExpoSystemUI::ensureSystemUIInitialized");
|
|
51
|
+
if (lazyDelegate) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
volta::react::ExpoUIManager expoUIManager;
|
|
56
|
+
lazyDelegate = std::make_unique<ExpoSystemUI>(expoUIManager);
|
|
57
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <KeplerScript/components/KeplerViewComponent.h>
|
|
10
|
+
#include <KeplerScript/modules/KeplerTurboModule.h>
|
|
11
|
+
#include <Volta/graphics/Color.h>
|
|
12
|
+
|
|
13
|
+
#include "ExpoSystemUI.h"
|
|
14
|
+
#include "ExpoUIManager.h"
|
|
15
|
+
|
|
16
|
+
class KEPLERSCRIPT_EXPORT ExpoSystemUITurboModule : public volta::react::KeplerTurboModule {
|
|
17
|
+
public:
|
|
18
|
+
ExpoSystemUITurboModule();
|
|
19
|
+
|
|
20
|
+
protected:
|
|
21
|
+
void aggregateMethods(
|
|
22
|
+
volta::react::MethodAggregator<volta::react::KeplerTurboModule>& methodAggregator) const noexcept override;
|
|
23
|
+
|
|
24
|
+
volta::react::Promise getBackgroundColorAsync();
|
|
25
|
+
volta::react::Promise resetBackgroundColorAsync();
|
|
26
|
+
volta::react::Promise setBackgroundColorAsync(int64_t color);
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
void ensureSystemUIInitialized();
|
|
30
|
+
|
|
31
|
+
std::unique_ptr<ExpoSystemUI> lazyDelegate;
|
|
32
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <KeplerScript/logger/KPLog.h>
|
|
10
|
+
#include <KeplerScript/utils/autolink/KeplerAutoLinkInfo.h>
|
|
11
|
+
#include <keplerui-072/keplerscript-export.h>
|
|
12
|
+
|
|
13
|
+
#include "ExpoSystemUITurboModule.h"
|
|
14
|
+
#include "RegisterModule.h"
|
|
15
|
+
|
|
16
|
+
extern "C" {
|
|
17
|
+
KEPLERSCRIPT_EXPORT void keplerAutoLinkInitV1(const kepler::autolink::v1::KeplerAutoLinkInfo* autoLinkInfo) noexcept {
|
|
18
|
+
volta::react::KPLog.debug("keplerAutoLinkInitV1 for ExpoSystemUI");
|
|
19
|
+
|
|
20
|
+
REGISTER_MODULE(autoLinkInfo, ExpoSystemUITurboModule, "ExpoSystemUI");
|
|
21
|
+
|
|
22
|
+
volta::react::KPLog.debug("after registering module");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
int main() {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* PROPRIETARY/CONFIDENTIAL
|
|
5
|
+
*
|
|
6
|
+
* Use is subject to license terms.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <JsonContainer/JsonContainer.h>
|
|
10
|
+
#include <KeplerScript/components/KeplerViewComponent.h>
|
|
11
|
+
#include <KeplerScript/modules/KeplerTurboModule.h>
|
|
12
|
+
#include <KeplerScript/modules/Promise.h>
|
|
13
|
+
#include <KeplerScript/private/modules/CallbackParameterTypes.h>
|
|
14
|
+
#include <gmock/gmock-actions.h>
|
|
15
|
+
#include <gmock/gmock.h>
|
|
16
|
+
#include <gtest/gtest.h>
|
|
17
|
+
|
|
18
|
+
#include <exception>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <variant>
|
|
21
|
+
|
|
22
|
+
#include "../ExpoSystemUITurboModule.h"
|
|
23
|
+
#include "JSObjectsConversion.h"
|
|
24
|
+
#include "catch.hpp"
|
|
25
|
+
#include "gtest/gtest.h"
|
|
26
|
+
|
|
27
|
+
namespace volta::react {
|
|
28
|
+
|
|
29
|
+
using namespace std::string_literals;
|
|
30
|
+
using CallbackArgs = std::vector<std::variant<CALLBACK_PARAM_SUPPORTED_TYPES>>;
|
|
31
|
+
|
|
32
|
+
namespace {
|
|
33
|
+
|
|
34
|
+
class MockKeplerUIManager : public IKeplerUIManager {
|
|
35
|
+
public:
|
|
36
|
+
MOCK_METHOD((std::shared_ptr<KeplerViewComponent>), getComponentViewByTag, (int32_t), (override));
|
|
37
|
+
MOCK_METHOD((bool), isOnUIThread, (), (override));
|
|
38
|
+
MOCK_METHOD((void), executeOnUIThread, (const std::function<void()>&), (override));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// TODO: uncomment and use once Callback and Promise become testable
|
|
42
|
+
// void reject(CallbackArgs& vargs) {
|
|
43
|
+
// std::string errorMsg;
|
|
44
|
+
// try {
|
|
45
|
+
// REQUIRE(vargs.size() == 1);
|
|
46
|
+
// auto& jsonContainer = std::get<utils::json::JsonContainer>(vargs.front());
|
|
47
|
+
// auto jsonMap = ExpoUtils::convertJsonContainerToNativeJSObject(jsonContainer);
|
|
48
|
+
// errorMsg = std::get<std::string>(jsonMap.at("message"));
|
|
49
|
+
// } catch (std::exception& e) {
|
|
50
|
+
// errorMsg = e.what();
|
|
51
|
+
// }
|
|
52
|
+
// FAIL("Promise invoked rejectedCallback: "s + errorMsg);
|
|
53
|
+
// }
|
|
54
|
+
|
|
55
|
+
// void evalPromise(const Promise& promise, std::function<void(CallbackArgs&)>&& resolve) {
|
|
56
|
+
// auto pAction = std::make_shared<Promise>(Callback(std::move(resolve)), Callback(reject));
|
|
57
|
+
// promise.promiseOperation_(pAction);
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
// auto getBackgroundColorSync(ExpoSystemUI& systemUI) {
|
|
61
|
+
// auto pColor = systemUI.getBackgroundColorAsync();
|
|
62
|
+
// std::string color;
|
|
63
|
+
// auto resolve = [&color](auto& vargs) {
|
|
64
|
+
// REQUIRE(vargs.size() == 1);
|
|
65
|
+
// color = std::get<std::string>(vargs.front());
|
|
66
|
+
// };
|
|
67
|
+
|
|
68
|
+
// evalPromise(pColor, resolve);
|
|
69
|
+
// return color;
|
|
70
|
+
// }
|
|
71
|
+
using testing::Ne;
|
|
72
|
+
using testing::Return;
|
|
73
|
+
|
|
74
|
+
ExpoSystemUIImpl createModule(const std::shared_ptr<KeplerViewComponent>& mockRootView) {
|
|
75
|
+
MockKeplerUIManager mock;
|
|
76
|
+
EXPECT_CALL(mock, getComponentViewByTag(Ne(1))).Times(0);
|
|
77
|
+
EXPECT_CALL(mock, getComponentViewByTag(1)).WillRepeatedly(Return(mockRootView));
|
|
78
|
+
return ExpoSystemUIImpl(mock);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
} // namespace
|
|
82
|
+
|
|
83
|
+
TEST_CASE("ExpoSystemUI fails to initialise") {
|
|
84
|
+
MockKeplerUIManager mock;
|
|
85
|
+
EXPECT_CALL(mock, getComponentViewByTag(Ne(1))).Times(0);
|
|
86
|
+
EXPECT_CALL(mock, getComponentViewByTag(1)).WillOnce(Return(nullptr));
|
|
87
|
+
REQUIRE_THROWS(ExpoSystemUI(mock));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
TEST_CASE("ExpoSystemUI") {
|
|
91
|
+
// setup
|
|
92
|
+
constexpr int iBlack = static_cast<int>(0xff000000);
|
|
93
|
+
constexpr int iWhite = static_cast<int>(0xffffffff);
|
|
94
|
+
const auto sBlack = "#000000"s;
|
|
95
|
+
const auto sWhite = "#ffffff"s; // outputs are case-sensitive
|
|
96
|
+
|
|
97
|
+
auto mockRootView = std::make_shared<KeplerViewComponent>();
|
|
98
|
+
mockRootView->setBackgroundColor(iBlack);
|
|
99
|
+
auto expoSystemUI = createModule(mockRootView);
|
|
100
|
+
|
|
101
|
+
SECTION("getBackgroundColorAsync") {
|
|
102
|
+
REQUIRE(mockRootView->getBackgroundColor() == volta::graphics::Color::Black);
|
|
103
|
+
REQUIRE(expoSystemUI.getBackgroundColor() == sBlack);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
SECTION("setBackgroundColorAsync") {
|
|
107
|
+
REQUIRE(mockRootView->getBackgroundColor() == volta::graphics::Color::Black);
|
|
108
|
+
REQUIRE(expoSystemUI.getBackgroundColor() == sBlack);
|
|
109
|
+
|
|
110
|
+
expoSystemUI.setBackgroundColor(iWhite);
|
|
111
|
+
|
|
112
|
+
REQUIRE(mockRootView->getBackgroundColor() == volta::graphics::Color::White);
|
|
113
|
+
REQUIRE(expoSystemUI.getBackgroundColor() == sWhite);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
SECTION("resetBackgroundColorAsync") {
|
|
117
|
+
REQUIRE(mockRootView->getBackgroundColor() == volta::graphics::Color::Black);
|
|
118
|
+
REQUIRE(expoSystemUI.getBackgroundColor() == sBlack);
|
|
119
|
+
|
|
120
|
+
mockRootView->setBackgroundColor(iWhite);
|
|
121
|
+
|
|
122
|
+
REQUIRE(mockRootView->getBackgroundColor() == volta::graphics::Color::White);
|
|
123
|
+
REQUIRE(expoSystemUI.getBackgroundColor() == sWhite);
|
|
124
|
+
|
|
125
|
+
expoSystemUI.resetBackgroundColor();
|
|
126
|
+
|
|
127
|
+
REQUIRE(mockRootView->getBackgroundColor() == volta::graphics::Color::Black);
|
|
128
|
+
REQUIRE(expoSystemUI.getBackgroundColor() == sBlack);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
TEST_CASE("ExpoSystemUITurboModule") {
|
|
133
|
+
ExpoSystemUITurboModule tmodule;
|
|
134
|
+
|
|
135
|
+
SECTION("aggregateMethods") {
|
|
136
|
+
std::weak_ptr<facebook::react::Instance> instance;
|
|
137
|
+
REQUIRE(tmodule.methodContainerMap_.empty());
|
|
138
|
+
|
|
139
|
+
tmodule.triggerMethodAggregation(*tmodule.jsQueue_, instance);
|
|
140
|
+
|
|
141
|
+
auto registeredMethods = {
|
|
142
|
+
"getBackgroundColorAsync",
|
|
143
|
+
"resetBackgroundColorAsync",
|
|
144
|
+
"setBackgroundColorAsync",
|
|
145
|
+
};
|
|
146
|
+
for (const auto& methodName : registeredMethods) {
|
|
147
|
+
REQUIRE(tmodule.methodContainerMap_.find(methodName) != tmodule.methodContainerMap_.end());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
REQUIRE(tmodule.methodContainerMap_.size() ==
|
|
151
|
+
registeredMethods.size() + 2); // "addListener" and "removeListeners" are added by default
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} // namespace volta::react
|
package/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "@amazon-devices/expo-system-ui", "version": "2.0.1758683737+2.7.0", "description": "Interact with system UI elements", "main": "build/SystemUI.js", "types": "build/SystemUI.d.ts", "scripts": {"build": "expo-module build", "clean": "expo-module clean", "lint": "expo-module lint", "test": "expo-module test", "expo-module": "expo-module"}, "kepler": {"temporary-alias-for-package": {"name": "expo-system-ui", "version": "2.7.0"}}, "keywords": ["react-native", "expo", "background-color", "user-interface", "appearance"], "repository": {"type": "git", "url": "https://github.com/expo/expo.git", "directory": "packages/expo-system-ui"}, "bugs": {"url": "https://github.com/expo/expo/issues"}, "author": "650 Industries, Inc.", "license": "See license in LICENSE", "homepage": "https://docs.expo.dev/versions/latest/sdk/system-ui", "dependencies": {"@react-native/normalize-color": "^2.0.0", "debug": "^4.3.2"}, "jest": {"preset": "expo-module-scripts"}, "devDependencies": {"expo-module-scripts": "^3.0.0"}, "peerDependencies": {"expo": "*"}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('expo-module-scripts/babel.config.plugin');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ExpoConfig } from 'expo/config';
|
|
2
|
+
import { ConfigPlugin } from 'expo/config-plugins';
|
|
3
|
+
export declare const withAndroidRootViewBackgroundColor: ConfigPlugin;
|
|
4
|
+
export declare const withRootViewBackgroundColorColors: ConfigPlugin;
|
|
5
|
+
export declare const withRootViewBackgroundColorStyles: ConfigPlugin;
|
|
6
|
+
export declare function getRootViewBackgroundColor(config: Pick<ExpoConfig, 'android' | 'backgroundColor'>): string | null;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withRootViewBackgroundColorStyles = exports.withRootViewBackgroundColorColors = exports.withAndroidRootViewBackgroundColor = void 0;
|
|
4
|
+
exports.getRootViewBackgroundColor = getRootViewBackgroundColor;
|
|
5
|
+
const config_plugins_1 = require("expo/config-plugins");
|
|
6
|
+
const { assignColorValue } = config_plugins_1.AndroidConfig.Colors;
|
|
7
|
+
const { assignStylesValue, getAppThemeLightNoActionBarGroup } = config_plugins_1.AndroidConfig.Styles;
|
|
8
|
+
const ANDROID_WINDOW_BACKGROUND = 'android:windowBackground';
|
|
9
|
+
const WINDOW_BACKGROUND_COLOR = 'activityBackground';
|
|
10
|
+
const withAndroidRootViewBackgroundColor = (config) => {
|
|
11
|
+
config = (0, exports.withRootViewBackgroundColorColors)(config);
|
|
12
|
+
config = (0, exports.withRootViewBackgroundColorStyles)(config);
|
|
13
|
+
return config;
|
|
14
|
+
};
|
|
15
|
+
exports.withAndroidRootViewBackgroundColor = withAndroidRootViewBackgroundColor;
|
|
16
|
+
const withRootViewBackgroundColorColors = (config) => {
|
|
17
|
+
return (0, config_plugins_1.withAndroidColors)(config, async (config) => {
|
|
18
|
+
config.modResults = assignColorValue(config.modResults, {
|
|
19
|
+
value: getRootViewBackgroundColor(config),
|
|
20
|
+
name: WINDOW_BACKGROUND_COLOR,
|
|
21
|
+
});
|
|
22
|
+
return config;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.withRootViewBackgroundColorColors = withRootViewBackgroundColorColors;
|
|
26
|
+
const withRootViewBackgroundColorStyles = (config) => {
|
|
27
|
+
return (0, config_plugins_1.withAndroidStyles)(config, async (config) => {
|
|
28
|
+
config.modResults = assignStylesValue(config.modResults, {
|
|
29
|
+
add: !!getRootViewBackgroundColor(config),
|
|
30
|
+
parent: getAppThemeLightNoActionBarGroup(),
|
|
31
|
+
name: ANDROID_WINDOW_BACKGROUND,
|
|
32
|
+
value: `@color/${WINDOW_BACKGROUND_COLOR}`,
|
|
33
|
+
});
|
|
34
|
+
return config;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
exports.withRootViewBackgroundColorStyles = withRootViewBackgroundColorStyles;
|
|
38
|
+
function getRootViewBackgroundColor(config) {
|
|
39
|
+
return config.android?.backgroundColor || config.backgroundColor || null;
|
|
40
|
+
}
|