@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.
Files changed (67) hide show
  1. package/.eslintrc.js +2 -0
  2. package/CHANGELOG.md +116 -0
  3. package/CMakeLists.txt +46 -0
  4. package/LICENSE +7 -0
  5. package/README.kepler.md +80 -0
  6. package/README.md +27 -0
  7. package/THIRD_PARTY_NOTICES.txt +24 -0
  8. package/android/build.gradle +112 -0
  9. package/android/src/main/AndroidManifest.xml +2 -0
  10. package/android/src/main/java/expo/modules/systemui/SystemUIModule.kt +74 -0
  11. package/android/src/main/java/expo/modules/systemui/SystemUIPackage.kt +11 -0
  12. package/android/src/main/java/expo/modules/systemui/SystemUIReactActivityLifecycleListener.kt +18 -0
  13. package/android/src/main/java/expo/modules/systemui/singletons/SystemUI.kt +36 -0
  14. package/android/src/main/res/values/strings.xml +4 -0
  15. package/app.plugin.js +1 -0
  16. package/build/ExpoSystemUI.d.ts +3 -0
  17. package/build/ExpoSystemUI.d.ts.map +1 -0
  18. package/build/ExpoSystemUI.js +3 -0
  19. package/build/ExpoSystemUI.js.map +1 -0
  20. package/build/ExpoSystemUI.kepler.d.ts +7 -0
  21. package/build/ExpoSystemUI.kepler.d.ts.map +1 -0
  22. package/build/ExpoSystemUI.kepler.js +14 -0
  23. package/build/ExpoSystemUI.kepler.js.map +1 -0
  24. package/build/ExpoSystemUI.web.d.ts +7 -0
  25. package/build/ExpoSystemUI.web.d.ts.map +1 -0
  26. package/build/ExpoSystemUI.web.js +22 -0
  27. package/build/ExpoSystemUI.web.js.map +1 -0
  28. package/build/SystemUI.d.ts +23 -0
  29. package/build/SystemUI.d.ts.map +1 -0
  30. package/build/SystemUI.js +34 -0
  31. package/build/SystemUI.js.map +1 -0
  32. package/expo-module.config.json +10 -0
  33. package/ios/ExpoSystemUI/ExpoSystemUIModule.swift +72 -0
  34. package/ios/ExpoSystemUI.podspec +31 -0
  35. package/kepler/ExpoSystemUI.cpp +47 -0
  36. package/kepler/ExpoSystemUI.h +29 -0
  37. package/kepler/ExpoSystemUIImpl.cpp +39 -0
  38. package/kepler/ExpoSystemUIImpl.h +29 -0
  39. package/kepler/ExpoSystemUITurboModule.cpp +57 -0
  40. package/kepler/ExpoSystemUITurboModule.h +32 -0
  41. package/kepler/KeplerInit.cpp +28 -0
  42. package/kepler/test/ExpoSystemUI.cpp +154 -0
  43. package/package.json +1 -0
  44. package/plugin/babel.config.js +1 -0
  45. package/plugin/build/withAndroidRootViewBackgroundColor.d.ts +6 -0
  46. package/plugin/build/withAndroidRootViewBackgroundColor.js +40 -0
  47. package/plugin/build/withAndroidUserInterfaceStyle.d.ts +8 -0
  48. package/plugin/build/withAndroidUserInterfaceStyle.js +42 -0
  49. package/plugin/build/withIosRootViewBackgroundColor.d.ts +5 -0
  50. package/plugin/build/withIosRootViewBackgroundColor.js +41 -0
  51. package/plugin/build/withIosUserInterfaceStyle.d.ts +5 -0
  52. package/plugin/build/withIosUserInterfaceStyle.js +38 -0
  53. package/plugin/build/withSystemUI.d.ts +3 -0
  54. package/plugin/build/withSystemUI.js +17 -0
  55. package/plugin/src/withAndroidRootViewBackgroundColor.ts +47 -0
  56. package/plugin/src/withAndroidUserInterfaceStyle.ts +53 -0
  57. package/plugin/src/withIosRootViewBackgroundColor.ts +41 -0
  58. package/plugin/src/withIosUserInterfaceStyle.ts +47 -0
  59. package/plugin/src/withSystemUI.ts +19 -0
  60. package/plugin/tsconfig.json +9 -0
  61. package/plugin/tsconfig.tsbuildinfo +1 -0
  62. package/react-native.config.js +21 -0
  63. package/src/ExpoSystemUI.kepler.ts +27 -0
  64. package/src/ExpoSystemUI.ts +2 -0
  65. package/src/ExpoSystemUI.web.ts +21 -0
  66. package/src/SystemUI.ts +35 -0
  67. package/tsconfig.json +9 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,2 @@
1
+ // @generated by expo-module-scripts
2
+ module.exports = require('expo-module-scripts/eslintrc.base.js');
package/CHANGELOG.md ADDED
@@ -0,0 +1,116 @@
1
+ # Changelog
2
+
3
+ ## Unpublished
4
+
5
+ ### 🛠 Breaking changes
6
+
7
+ ### 🎉 New features
8
+
9
+ ### 🐛 Bug fixes
10
+
11
+ ### 💡 Others
12
+
13
+ ## 2.7.0 — 2023-10-17
14
+
15
+ ### 🛠 Breaking changes
16
+
17
+ - Dropped support for Android SDK 21 and 22. ([#24201](https://github.com/expo/expo/pull/24201) by [@behenate](https://github.com/behenate))
18
+
19
+ ## 2.6.0 — 2023-09-04
20
+
21
+ ### 🎉 New features
22
+
23
+ - Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
24
+
25
+ ## 2.5.0 — 2023-08-02
26
+
27
+ _This version does not introduce any user-facing changes._
28
+
29
+ ## 2.4.0 — 2023-06-21
30
+
31
+ ### 🎉 New features
32
+
33
+ - Persist user selected background color and restore automatically on iOS. Added `restoreBackgroundColorAsync` to restore it on Android. ([#22773](https://github.com/expo/expo/pull/22773) by [@alanhughes](https://github.com/alanjhughes))
34
+
35
+ ### 🐛 Bug fixes
36
+
37
+ - Fixed Android build warnings for Gradle version 8. ([#22537](https://github.com/expo/expo/pull/22537), [#22609](https://github.com/expo/expo/pull/22609) by [@kudo](https://github.com/kudo))
38
+
39
+ ## 2.3.0 — 2023-05-08
40
+
41
+ ### 💡 Others
42
+
43
+ - Android: Switch from deprecated `toLowerCase` to `lowercase` function ([#22225](https://github.com/expo/expo/pull/22225) by [@hbiede](https://github.com/hbiede))
44
+
45
+ ## 2.2.1 — 2023-02-09
46
+
47
+ _This version does not introduce any user-facing changes._
48
+
49
+ ## 2.2.0 — 2023-02-03
50
+
51
+ ### 💡 Others
52
+
53
+ - On Android bump `compileSdkVersion` and `targetSdkVersion` to `33`. ([#20721](https://github.com/expo/expo/pull/20721) by [@lukmccall](https://github.com/lukmccall))
54
+
55
+ ## 2.1.0 — 2022-12-30
56
+
57
+ ### 🎉 New features
58
+
59
+ - Migrated Android codebase to use the new Expo modules API. ([#20221](https://github.com/expo/expo/pull/20221) by [@alanhughes](https://github.com/alanjhughes))
60
+
61
+ ## 2.0.1 — 2022-10-28
62
+
63
+ _This version does not introduce any user-facing changes._
64
+
65
+ ## 2.0.0 — 2022-10-25
66
+
67
+ ### 🛠 Breaking changes
68
+
69
+ - [plugin] Upgrade minimum runtime requirement to Node 14 (LTS). ([#18204](https://github.com/expo/expo/pull/18204) by [@EvanBacon](https://github.com/EvanBacon))
70
+ - Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
71
+
72
+ ### 💡 Others
73
+
74
+ - [plugin] Migrate import from @expo/config-plugins to expo/config-plugins and @expo/config-types to expo/config. ([#18855](https://github.com/expo/expo/pull/18855) by [@brentvatne](https://github.com/brentvatne))
75
+ - Drop `@expo/config-plugins` dependency in favor of peer dependency on `expo`. ([#18595](https://github.com/expo/expo/pull/18595) by [@EvanBacon](https://github.com/EvanBacon))
76
+
77
+ ## 1.3.0 — 2022-07-07
78
+
79
+ ### 🐛 Bug fixes
80
+
81
+ - Fix color setting on web. ([#17558](https://github.com/expo/expo/pull/17558) by [@EvanBacon](https://github.com/EvanBacon))
82
+
83
+ ### 💡 Others
84
+
85
+ - Migrated Expo modules definitions to the new naming convention. ([#17193](https://github.com/expo/expo/pull/17193) by [@tsapeta](https://github.com/tsapeta))
86
+
87
+ ## 1.2.0 — 2022-04-18
88
+
89
+ ### 💡 Others
90
+
91
+ - Updated `@expo/config-plugins` from `4.0.2` to `4.0.14` ([#15621](https://github.com/expo/expo/pull/15621) by [@EvanBacon](https://github.com/EvanBacon))
92
+
93
+ ### ⚠️ Notices
94
+
95
+ - On Android bump `compileSdkVersion` to `31`, `targetSdkVersion` to `31` and `Java` version to `11`. ([#16941](https://github.com/expo/expo/pull/16941) by [@bbarthec](https://github.com/bbarthec))
96
+
97
+ ## 1.1.1 - 2022-02-01
98
+
99
+ ### 🐛 Bug fixes
100
+
101
+ - Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
102
+
103
+ ## 1.1.0 — 2021-12-03
104
+
105
+ ### 🛠 Breaking changes
106
+
107
+ - Change iOS to set the background color of the first view controller in the hierarchy instead of the current active view controller. ([#15146](https://github.com/expo/expo/pull/15146) by [@EvanBacon](https://github.com/EvanBacon))
108
+
109
+ ### 🎉 New features
110
+
111
+ - iOS now sets the background color of the base window to support native-stack modals. ([#15146](https://github.com/expo/expo/pull/15146) by [@EvanBacon](https://github.com/EvanBacon))
112
+ - Initial background color on iOS will now be set inside the module instead of in the template. ([#15146](https://github.com/expo/expo/pull/15146) by [@EvanBacon](https://github.com/EvanBacon))
113
+
114
+ ### 🐛 Bug fixes
115
+
116
+ - Fix `getBackgroundColorAsync` return type. ([#15127](https://github.com/expo/expo/pull/15127) by [@EvanBacon](https://github.com/EvanBacon))
package/CMakeLists.txt ADDED
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright 2024 Amazon.com, Inc. or its affiliates. All rights reserved.
3
+ #
4
+ # AMAZON PROPRIETARY/CONFIDENTIAL
5
+ #
6
+ # You may not use this file except in compliance with the terms and conditions
7
+ # set forth in the accompanying LICENSE.TXT file.
8
+ #
9
+ # THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
10
+ # DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
11
+ # IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
12
+ # FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
13
+ #
14
+ set(PACKAGE_NAME "expo-system-ui")
15
+ set(AUTO_LINK_PACKAGE_NAME "${PACKAGE_NAME}-${KEPLER_REACT_NATIVE_MAJOR_VERSION}")
16
+ set(SOURCES_KEPLER kepler/ExpoSystemUIImpl.cpp kepler/ExpoSystemUI.cpp kepler/ExpoSystemUITurboModule.cpp)
17
+
18
+ add_library(${PACKAGE_NAME} STATIC ${SOURCES_KEPLER})
19
+
20
+ target_link_libraries(
21
+ ${PACKAGE_NAME}
22
+ PUBLIC
23
+ keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
24
+ )
25
+
26
+ add_library(${AUTO_LINK_PACKAGE_NAME} SHARED kepler/KeplerInit.cpp)
27
+
28
+ set_target_properties(${AUTO_LINK_PACKAGE_NAME} PROPERTIES SOVERSION ${KEPLER_REACT_NATIVE_MAJOR_VERSION}.${KEPLER_REACT_NATIVE_MINOR_VERSION})
29
+
30
+ target_link_libraries(
31
+ ${AUTO_LINK_PACKAGE_NAME}
32
+ PRIVATE
33
+ ${PACKAGE_NAME}
34
+ )
35
+
36
+ # Helps in checking undefined references
37
+ add_executable(${AUTO_LINK_PACKAGE_NAME}_exe kepler/KeplerInit.cpp)
38
+ target_link_libraries(${AUTO_LINK_PACKAGE_NAME}_exe
39
+ PRIVATE
40
+ ${AUTO_LINK_PACKAGE_NAME}
41
+ keplerui::keplerscript-${KEPLER_REACT_NATIVE_MAJOR_VERSION}
42
+ )
43
+
44
+ install(TARGETS ${AUTO_LINK_PACKAGE_NAME}
45
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
46
+ )
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
2
+
3
+ These materials are licensed as "Program Materials" under the Program Materials License Agreement (the "Agreement"). The Agreement is available at https://developer.amazon.com/support/legal/pml. See the Agreement for the specific terms and conditions of the Agreement. Capitalized terms not defined in this file have the meanings given to them in the Agreement.
4
+
5
+ If you do not agree to the above terms and conditions, you may not use any file in this package.
6
+
7
+ YOUR USE OF THE PROGRAM MATERIALS IN OR ASSOCIATED WITH THIS PACKAGE IS AT YOUR SOLE RISK. IN NO EVENT WILL AMAZON BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION ANY DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL, INCIDENTAL, OR PUNITIVE DAMAGES (INCLUDING FOR ANY LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS OR DATA, OR COMPUTER FAILURE OR MALFUNCTION) ARISING FROM OR RELATING TO SUCH PROGRAM MATERIALS, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, EVEN IF AMAZON HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS AND DISCLAIMERS APPLY EXCEPT TO THE EXTENT PROHIBITED BY APPLICABLE LAW.
@@ -0,0 +1,80 @@
1
+ # @amazon-devices/expo-system-ui
2
+
3
+ ## Getting Started
4
+
5
+ `@amazon-devices/expo-system-ui` allows interacting with system UI elements that fall outside of the React tree. Specifically the root view background color.
6
+
7
+ ### Installation
8
+
9
+ 1. Add the JavaScript library dependency in the `package.json` file:
10
+ ```json
11
+ dependencies: {
12
+ ...
13
+ "@amazon-devices/expo-system-ui": "~2.0.0",
14
+ "@amazon-devices/keplerscript-turbomodule-api": "^1.0.0",
15
+ ...
16
+ }
17
+ ```
18
+
19
+ 2. Reinstall dependencies using `npm install` command.
20
+
21
+ ## Usage Examples
22
+
23
+ ```js
24
+ import React, {useState} from 'react';
25
+ import {StyleSheet, View, Button} from 'react-native';
26
+ import * as SystemUI from '@amazon-devices/expo-system-ui';
27
+ import {ColorValue} from 'react-native';
28
+
29
+ export const App = () => {
30
+ const [backgroundColor, setBackgroundColor] = useState<ColorValue | null>(
31
+ '#0000ff',
32
+ );
33
+
34
+ const changeBackgroundColor = async (color: string | null) => {
35
+ console.log(backgroundColor);
36
+ await SystemUI.setBackgroundColorAsync(color);
37
+ setBackgroundColor(await SystemUI.getBackgroundColorAsync());
38
+ };
39
+
40
+ return (
41
+ <View style={[styles.container, backgroundColor ? {backgroundColor} : {}]}>
42
+ <Button
43
+ title="Change background color"
44
+ onPress={() =>
45
+ changeBackgroundColor(
46
+ backgroundColor === '#0000ff' ? '#ff0000' : '#0000ff',
47
+ )
48
+ }
49
+ />
50
+ </View>
51
+ );
52
+ };
53
+
54
+ const styles = StyleSheet.create({
55
+ container: {
56
+ flex: 1,
57
+ alignItems: 'center',
58
+ justifyContent: 'center',
59
+ },
60
+ });
61
+
62
+
63
+ ```
64
+
65
+ ## API Documentation
66
+
67
+ Check out the dedicated documentation page for info about this library, API reference and more: [Official Expo documentation for expo-system-ui](https://github.com/expo/expo/blob/sdk-49/docs/pages/versions/v49.0.0/sdk/system-ui.mdx).
68
+
69
+ ### Methods
70
+
71
+ | Method | Description | Platform support |
72
+ | ------ | ----------- | ---------------- |
73
+ | getBackgroundColorAsync | Gets the root view background color | All |
74
+ | setBackgroundColorAsync | Changes the root view background color | All |
75
+
76
+ ## Supported Versions
77
+
78
+ | Package version | Based on | @amazon-devices/react-native-kepler version |
79
+ | ---------------- | -------- | --------------------------------- |
80
+ | 2.0.x | expo-system-ui v2.7.0 | 2.0.x |
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # expo-system-ui
2
+
3
+ **`expo-system-ui`** adds support for locking the user interface (appearance) and updating the root view background color.
4
+
5
+ ## API documentation
6
+
7
+ - [Documentation for the main branch][docs-main]
8
+ - [Documentation for the latest stable release][docs-stable]
9
+
10
+ ### Installation
11
+
12
+ ```
13
+ npx expo install expo-system-ui
14
+ ```
15
+
16
+ ### Extra Setup
17
+
18
+ For bare React Native projects, ensure that you have the [native `expo` package][expo-modules] setup before continuing, this is required for all Expo modules.
19
+
20
+ ## Contributing
21
+
22
+ Contributions are very welcome! Please refer to guidelines described in the [contributing guide][contributing].
23
+
24
+ [docs-main]: https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/system-ui.mdx
25
+ [docs-stable]: https://docs.expo.dev/versions/latest/sdk/system-ui/
26
+ [contributing]: https://github.com/expo/expo#contributing
27
+ [expo-modules]: https://docs.expo.dev/bare/installing-expo-modules/
@@ -0,0 +1,24 @@
1
+ License from package.json:
2
+ ==============================
3
+
4
+ The MIT License (MIT)
5
+
6
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
@@ -0,0 +1,112 @@
1
+ apply plugin: 'com.android.library'
2
+ apply plugin: 'kotlin-android'
3
+ apply plugin: 'maven-publish'
4
+
5
+ group = 'host.exp.exponent'
6
+ version = '2.7.0'
7
+
8
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
9
+ if (expoModulesCorePlugin.exists()) {
10
+ apply from: expoModulesCorePlugin
11
+ applyKotlinExpoModulesCorePlugin()
12
+ // Remove this check, but keep the contents after SDK49 support is dropped
13
+ if (safeExtGet("expoProvidesDefaultConfig", false)) {
14
+ useExpoPublishing()
15
+ useCoreDependencies()
16
+ }
17
+ }
18
+
19
+ buildscript {
20
+ // Simple helper that allows the root project to override versions declared by this library.
21
+ ext.safeExtGet = { prop, fallback ->
22
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
23
+ }
24
+
25
+ // Ensures backward compatibility
26
+ ext.getKotlinVersion = {
27
+ if (ext.has("kotlinVersion")) {
28
+ ext.kotlinVersion()
29
+ } else {
30
+ ext.safeExtGet("kotlinVersion", "1.8.10")
31
+ }
32
+ }
33
+
34
+ repositories {
35
+ mavenCentral()
36
+ }
37
+
38
+ dependencies {
39
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
40
+ }
41
+ }
42
+
43
+ // Remove this if and it's contents, when support for SDK49 is dropped
44
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
45
+ afterEvaluate {
46
+ publishing {
47
+ publications {
48
+ release(MavenPublication) {
49
+ from components.release
50
+ }
51
+ }
52
+ repositories {
53
+ maven {
54
+ url = mavenLocal().url
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ android {
62
+ // Remove this if and it's contents, when support for SDK49 is dropped
63
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
64
+ compileSdkVersion safeExtGet("compileSdkVersion", 33)
65
+
66
+ defaultConfig {
67
+ minSdkVersion safeExtGet("minSdkVersion", 23)
68
+ targetSdkVersion safeExtGet("targetSdkVersion", 33)
69
+ }
70
+
71
+ publishing {
72
+ singleVariant("release") {
73
+ withSourcesJar()
74
+ }
75
+ }
76
+
77
+ lintOptions {
78
+ abortOnError false
79
+ }
80
+ }
81
+
82
+ def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
83
+ if (agpVersion.tokenize('.')[0].toInteger() < 8) {
84
+ compileOptions {
85
+ sourceCompatibility JavaVersion.VERSION_11
86
+ targetCompatibility JavaVersion.VERSION_11
87
+ }
88
+
89
+ kotlinOptions {
90
+ jvmTarget = JavaVersion.VERSION_11.majorVersion
91
+ }
92
+ }
93
+
94
+ namespace "expo.modules.systemui"
95
+ defaultConfig {
96
+ versionCode 1
97
+ versionName '2.7.0'
98
+ }
99
+ }
100
+
101
+ dependencies {
102
+ // Remove this if and it's contents, when support for SDK49 is dropped
103
+ if (!safeExtGet("expoProvidesDefaultConfig", false)) {
104
+ implementation project(':expo-modules-core')
105
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
106
+ }
107
+
108
+ //noinspection GradleDynamicVersion
109
+ implementation 'com.facebook.react:react-native:+'
110
+ implementation 'androidx.core:core:1.6.0'
111
+ implementation 'androidx.appcompat:appcompat:1.2.0'
112
+ }
@@ -0,0 +1,2 @@
1
+ <manifest>
2
+ </manifest>
@@ -0,0 +1,74 @@
1
+ package expo.modules.systemui
2
+
3
+ import android.content.Context
4
+ import android.content.SharedPreferences
5
+ import android.content.res.Configuration
6
+ import android.graphics.Color
7
+ import android.graphics.drawable.ColorDrawable
8
+ import androidx.appcompat.app.AppCompatDelegate
9
+ import expo.modules.kotlin.exception.Exceptions
10
+ import expo.modules.kotlin.functions.Queues
11
+ import expo.modules.kotlin.modules.Module
12
+ import expo.modules.kotlin.modules.ModuleDefinition
13
+
14
+ const val PREFERENCE_KEY = "expoRootBackgroundColor"
15
+
16
+ class SystemUIModule : Module() {
17
+ private val currentActivity
18
+ get() = appContext.currentActivity ?: throw Exceptions.MissingActivity()
19
+ private val context: Context
20
+ get() = appContext.reactContext ?: throw Exceptions.ReactContextLost()
21
+ private val prefs: SharedPreferences
22
+ get() = context.getSharedPreferences("expo_ui_preferences", Context.MODE_PRIVATE)
23
+ ?: throw Exceptions.ReactContextLost()
24
+
25
+ private val systemBackgroundColor
26
+ get() = when (AppCompatDelegate.getDefaultNightMode()) {
27
+ AppCompatDelegate.MODE_NIGHT_YES -> Color.BLACK
28
+ AppCompatDelegate.MODE_NIGHT_NO -> Color.WHITE
29
+ AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM -> {
30
+ when (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
31
+ Configuration.UI_MODE_NIGHT_YES -> Color.BLACK
32
+ Configuration.UI_MODE_NIGHT_NO -> Color.WHITE
33
+ else -> Color.WHITE
34
+ }
35
+ }
36
+ else -> Color.WHITE
37
+ }
38
+
39
+ override fun definition() = ModuleDefinition {
40
+ Name("ExpoSystemUI")
41
+
42
+ AsyncFunction("setBackgroundColorAsync") { color: Int? ->
43
+ color?.let {
44
+ prefs.edit()
45
+ .putInt(PREFERENCE_KEY, it)
46
+ .apply()
47
+ } ?: prefs.edit()
48
+ .remove(PREFERENCE_KEY)
49
+ .apply()
50
+ setBackgroundColor(color ?: systemBackgroundColor)
51
+ }.runOnQueue(Queues.MAIN)
52
+
53
+ AsyncFunction("getBackgroundColorAsync") {
54
+ val background = currentActivity.window.decorView.background
55
+ return@AsyncFunction if (background is ColorDrawable) {
56
+ colorToHex((background.mutate() as ColorDrawable).color)
57
+ } else {
58
+ null
59
+ }
60
+ }
61
+ }
62
+
63
+ private fun setBackgroundColor(color: Int) {
64
+ val rootView = currentActivity.window?.decorView
65
+ val colorInt = Color.parseColor(colorToHex(color))
66
+ rootView?.setBackgroundColor(colorInt)
67
+ }
68
+
69
+ companion object {
70
+ fun colorToHex(color: Int): String {
71
+ return String.format("#%02x%02x%02x", Color.red(color), Color.green(color), Color.blue(color))
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,11 @@
1
+ package expo.modules.systemui
2
+
3
+ import android.content.Context
4
+ import expo.modules.core.interfaces.Package
5
+ import expo.modules.core.interfaces.ReactActivityLifecycleListener
6
+
7
+ class SystemUIPackage : Package {
8
+ override fun createReactActivityLifecycleListeners(activityContext: Context): List<ReactActivityLifecycleListener> {
9
+ return listOf(SystemUIReactActivityLifecycleListener(activityContext))
10
+ }
11
+ }
@@ -0,0 +1,18 @@
1
+ package expo.modules.systemui
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.os.Bundle
6
+ import expo.modules.core.interfaces.ReactActivityLifecycleListener
7
+ import expo.modules.systemui.singletons.SystemUI
8
+
9
+ // EXPO_VERSIONING_NEEDS_EXPOVIEW_R
10
+
11
+ class SystemUIReactActivityLifecycleListener(activityContext: Context) : ReactActivityLifecycleListener {
12
+ override fun onCreate(activity: Activity, savedInstanceState: Bundle?) {
13
+ SystemUI.setUserInterfaceStyle(getUserInterfaceStyle(activity))
14
+ }
15
+
16
+ private fun getUserInterfaceStyle(context: Context): String =
17
+ context.getString(R.string.expo_system_ui_user_interface_style).lowercase()
18
+ }
@@ -0,0 +1,36 @@
1
+ package expo.modules.systemui.singletons
2
+
3
+ import android.os.Build
4
+ import android.util.Log
5
+ import androidx.appcompat.app.AppCompatDelegate
6
+
7
+ object SystemUI {
8
+ private const val TAG = "SystemUI"
9
+
10
+ private fun setUserInterfaceStyle(
11
+ style: String?,
12
+ successCallback: () -> Unit,
13
+ failureCallback: (reason: String) -> Unit
14
+ ) {
15
+
16
+ val mode = if (style == null) {
17
+ AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
18
+ } else when (style) {
19
+ "automatic" -> {
20
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
21
+ AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
22
+ } else AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
23
+ }
24
+ "dark" -> AppCompatDelegate.MODE_NIGHT_YES
25
+ "", "light" -> AppCompatDelegate.MODE_NIGHT_NO
26
+ else -> return failureCallback("Invalid user interface style: \"$style\"")
27
+ }
28
+ AppCompatDelegate.setDefaultNightMode(mode)
29
+ successCallback()
30
+ }
31
+
32
+ @JvmStatic
33
+ fun setUserInterfaceStyle(style: String) {
34
+ setUserInterfaceStyle(style, {}, { m -> Log.e(TAG, m) })
35
+ }
36
+ }
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="expo_system_ui_user_interface_style" translatable="false">light</string>
4
+ </resources>
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./plugin/build/withSystemUI');
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+ export default _default;
3
+ //# sourceMappingURL=ExpoSystemUI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSystemUI.d.ts","sourceRoot":"","sources":["../src/ExpoSystemUI.ts"],"names":[],"mappings":";AACA,wBAAmD"}
@@ -0,0 +1,3 @@
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ export default requireNativeModule('ExpoSystemUI');
3
+ //# sourceMappingURL=ExpoSystemUI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSystemUI.js","sourceRoot":"","sources":["../src/ExpoSystemUI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,eAAe,mBAAmB,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nexport default requireNativeModule('ExpoSystemUI');\n"]}
@@ -0,0 +1,7 @@
1
+ interface KeplerSystemUI {
2
+ readonly getBackgroundColorAsync: () => Promise<string | null>;
3
+ readonly setBackgroundColorAsync: (color: number | null) => Promise<void | null>;
4
+ }
5
+ declare const module: KeplerSystemUI;
6
+ export default module;
7
+ //# sourceMappingURL=ExpoSystemUI.kepler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSystemUI.kepler.d.ts","sourceRoot":"","sources":["../src/ExpoSystemUI.kepler.ts"],"names":[],"mappings":"AAUA,UAAU,cAAc;IACtB,QAAQ,CAAC,uBAAuB,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/D,QAAQ,CAAC,uBAAuB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;CAClF;AAED,QAAA,MAAM,MAAM,EAAE,cASb,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { TurboModuleRegistry } from '@amazon-devices/keplerscript-turbomodule-api';
2
+ const nativeModule = TurboModuleRegistry.getEnforcing('ExpoSystemUI');
3
+ const module = {
4
+ async getBackgroundColorAsync() {
5
+ return nativeModule.getBackgroundColorAsync();
6
+ },
7
+ async setBackgroundColorAsync(color) {
8
+ return color
9
+ ? nativeModule.setBackgroundColorAsync(color)
10
+ : nativeModule.resetBackgroundColorAsync();
11
+ },
12
+ };
13
+ export default module;
14
+ //# sourceMappingURL=ExpoSystemUI.kepler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSystemUI.kepler.js","sourceRoot":"","sources":["../src/ExpoSystemUI.kepler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAQ5F,MAAM,YAAY,GAAG,mBAAmB,CAAC,YAAY,CAAO,cAAc,CAAS,CAAC;AAOpF,MAAM,MAAM,GAAmB;IAC7B,KAAK,CAAC,uBAAuB;QAC3B,OAAO,YAAY,CAAC,uBAAuB,EAAE,CAAC;IAChD,CAAC;IACD,KAAK,CAAC,uBAAuB,CAAC,KAAoB;QAChD,OAAO,KAAK;YACV,CAAC,CAAC,YAAY,CAAC,uBAAuB,CAAC,KAAK,CAAC;YAC7C,CAAC,CAAC,YAAY,CAAC,yBAAyB,EAAE,CAAC;IAC/C,CAAC;CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import { KeplerTurboModule, TurboModuleRegistry } from '@amazon-devices/keplerscript-turbomodule-api';\n\ninterface Spec extends KeplerTurboModule {\n readonly getBackgroundColorAsync: () => Promise<string>;\n readonly resetBackgroundColorAsync: () => Promise<void>;\n readonly setBackgroundColorAsync: (color: number) => Promise<void>;\n}\n\nconst nativeModule = TurboModuleRegistry.getEnforcing<Spec>('ExpoSystemUI') as Spec;\n\ninterface KeplerSystemUI {\n readonly getBackgroundColorAsync: () => Promise<string | null>;\n readonly setBackgroundColorAsync: (color: number | null) => Promise<void | null>;\n}\n\nconst module: KeplerSystemUI = {\n async getBackgroundColorAsync() {\n return nativeModule.getBackgroundColorAsync();\n },\n async setBackgroundColorAsync(color: number | null) {\n return color\n ? nativeModule.setBackgroundColorAsync(color)\n : nativeModule.resetBackgroundColorAsync();\n },\n};\n\nexport default module;\n"]}
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ readonly name: string;
3
+ getBackgroundColorAsync(): any;
4
+ setBackgroundColorAsync(color: string | null): void;
5
+ };
6
+ export default _default;
7
+ //# sourceMappingURL=ExpoSystemUI.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoSystemUI.web.d.ts","sourceRoot":"","sources":["../src/ExpoSystemUI.web.ts"],"names":[],"mappings":";mBAKc,MAAM;;mCAUa,MAAM,GAAG,IAAI;;AAX9C,wBAgBE"}
@@ -0,0 +1,22 @@
1
+ import { Platform } from 'expo-modules-core';
2
+ // @ts-ignore: untyped
3
+ import normalizeColor from 'react-native-web/dist/cjs/modules/normalizeColor';
4
+ export default {
5
+ get name() {
6
+ return 'ExpoSystemUI';
7
+ },
8
+ getBackgroundColorAsync() {
9
+ if (Platform.isDOMAvailable) {
10
+ return normalizeColor(document.body.style.backgroundColor);
11
+ }
12
+ else {
13
+ return null;
14
+ }
15
+ },
16
+ setBackgroundColorAsync(color) {
17
+ if (Platform.isDOMAvailable) {
18
+ document.body.style.backgroundColor = color ?? 'white';
19
+ }
20
+ },
21
+ };
22
+ //# sourceMappingURL=ExpoSystemUI.web.js.map