expo-system-ui 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 2.1.0 — 2022-12-30
14
+
15
+ ### 🎉 New features
16
+
17
+ - Migrated Android codebase to use the new Expo modules API. ([#20221](https://github.com/expo/expo/pull/20221) by [@alanhughes](https://github.com/alanjhughes))
18
+
19
+ ## 2.0.1 — 2022-10-28
20
+
21
+ _This version does not introduce any user-facing changes._
22
+
13
23
  ## 2.0.0 — 2022-10-25
14
24
 
15
25
  ### 🛠 Breaking changes
package/README.md CHANGED
@@ -21,7 +21,7 @@ For bare React Native projects, ensure that you have the [native `expo` package]
21
21
 
22
22
  Contributions are very welcome! Please refer to guidelines described in the [contributing guide][contributing].
23
23
 
24
- [docs-main]: https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/system-ui.md
24
+ [docs-main]: https://github.com/expo/expo/blob/main/docs/pages/versions/unversioned/sdk/system-ui.mdx
25
25
  [docs-stable]: https://docs.expo.dev/versions/latest/sdk/system-ui/
26
26
  [contributing]: https://github.com/expo/expo#contributing
27
27
  [expo-modules]: https://docs.expo.dev/bare/installing-expo-modules/
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '2.0.0'
6
+ version = '2.1.0'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -74,7 +74,7 @@ android {
74
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
75
  targetSdkVersion safeExtGet("targetSdkVersion", 31)
76
76
  versionCode 1
77
- versionName '2.0.0'
77
+ versionName '2.1.0'
78
78
  }
79
79
  lintOptions {
80
80
  abortOnError false
@@ -1,75 +1,36 @@
1
1
  package expo.modules.systemui
2
2
 
3
- import android.app.Activity
4
- import android.content.Context
5
3
  import android.graphics.Color
6
4
  import android.graphics.drawable.ColorDrawable
7
- import android.util.Log
8
- import expo.modules.core.ExportedModule
9
- import expo.modules.core.ModuleRegistry
10
- import expo.modules.core.Promise
11
- import expo.modules.core.errors.CurrentActivityNotFoundException
12
- import expo.modules.core.interfaces.ActivityProvider
13
- import expo.modules.core.interfaces.ExpoMethod
14
-
15
- class SystemUIModule(context: Context) : ExportedModule(context) {
16
-
17
- private lateinit var activityProvider: ActivityProvider
18
-
19
- override fun getName(): String {
20
- return NAME
21
- }
22
-
23
- override fun onCreate(moduleRegistry: ModuleRegistry) {
24
- activityProvider = moduleRegistry.getModule(ActivityProvider::class.java)
25
- ?: throw IllegalStateException("Could not find implementation for ActivityProvider.")
26
- }
27
-
28
- // Ensure that rejections are passed up to JS rather than terminating the native client.
29
- private fun safeRunOnUiThread(promise: Promise, block: (activity: Activity) -> Unit) {
30
- val activity = activityProvider.currentActivity
31
- if (activity == null) {
32
- promise.reject(CurrentActivityNotFoundException())
33
- return
34
- }
35
- activity.runOnUiThread {
36
- block(activity)
37
- }
38
- }
39
-
40
- @ExpoMethod
41
- fun setBackgroundColorAsync(color: Int, promise: Promise) {
42
- safeRunOnUiThread(promise) {
43
- var rootView = it.window.decorView
44
- var colorString = colorToHex(color)
45
- try {
46
- val color = Color.parseColor(colorString)
47
- rootView.setBackgroundColor(color)
48
- promise.resolve(null)
49
- } catch (e: Throwable) {
50
- Log.e(ERROR_TAG, e.toString())
51
- rootView.setBackgroundColor(Color.WHITE)
52
- promise.reject(ERROR_TAG, "Invalid color: \"$color\"")
53
- }
54
- }
55
- }
56
-
57
- @ExpoMethod
58
- fun getBackgroundColorAsync(promise: Promise) {
59
- safeRunOnUiThread(promise) {
60
- var mBackground = it.window.decorView.background
61
- if (mBackground is ColorDrawable) {
62
- promise.resolve(colorToHex((mBackground.mutate() as ColorDrawable).color))
5
+ import expo.modules.kotlin.exception.Exceptions
6
+ import expo.modules.kotlin.functions.Queues
7
+ import expo.modules.kotlin.modules.Module
8
+ import expo.modules.kotlin.modules.ModuleDefinition
9
+
10
+ class SystemUIModule : Module() {
11
+ private val currentActivity
12
+ get() = appContext.currentActivity ?: throw Exceptions.MissingActivity()
13
+
14
+ override fun definition() = ModuleDefinition {
15
+ Name("ExpoSystemUI")
16
+
17
+ AsyncFunction("setBackgroundColorAsync") { color: Int ->
18
+ val rootView = currentActivity.window.decorView
19
+ val colorInt = Color.parseColor(colorToHex(color))
20
+ rootView.setBackgroundColor(colorInt)
21
+ }.runOnQueue(Queues.MAIN)
22
+
23
+ AsyncFunction("getBackgroundColorAsync") {
24
+ val background = currentActivity.window.decorView.background
25
+ return@AsyncFunction if (background is ColorDrawable) {
26
+ colorToHex((background.mutate() as ColorDrawable).color)
63
27
  } else {
64
- promise.resolve(null)
28
+ null
65
29
  }
66
30
  }
67
31
  }
68
32
 
69
33
  companion object {
70
- private const val NAME = "ExpoSystemUI"
71
- private const val ERROR_TAG = "ERR_SYSTEM_UI"
72
-
73
34
  fun colorToHex(color: Int): String {
74
35
  return String.format("#%02x%02x%02x", Color.red(color), Color.green(color), Color.blue(color))
75
36
  }
@@ -1,14 +1,10 @@
1
1
  package expo.modules.systemui
2
2
 
3
3
  import android.content.Context
4
- import expo.modules.core.BasePackage
5
- import expo.modules.core.ExportedModule
4
+ import expo.modules.core.interfaces.Package
6
5
  import expo.modules.core.interfaces.ReactActivityLifecycleListener
7
6
 
8
- class SystemUIPackage : BasePackage() {
9
- override fun createExportedModules(context: Context): List<ExportedModule> {
10
- return listOf(SystemUIModule(context) as ExportedModule)
11
- }
7
+ class SystemUIPackage : Package {
12
8
  override fun createReactActivityLifecycleListeners(activityContext: Context): List<ReactActivityLifecycleListener> {
13
9
  return listOf(SystemUIReactActivityLifecycleListener(activityContext))
14
10
  }
@@ -4,6 +4,7 @@ import android.app.Activity
4
4
  import android.content.Context
5
5
  import android.os.Bundle
6
6
  import expo.modules.core.interfaces.ReactActivityLifecycleListener
7
+ import expo.modules.systemui.singletons.SystemUI
7
8
 
8
9
  // EXPO_VERSIONING_NEEDS_EXPOVIEW_R
9
10
 
@@ -1,4 +1,4 @@
1
- package expo.modules.systemui
1
+ package expo.modules.systemui.singletons
2
2
 
3
3
  import android.os.Build
4
4
  import android.util.Log
@@ -1,3 +1,3 @@
1
- declare const _default: import("expo-modules-core").ProxyNativeModule;
1
+ declare const _default: any;
2
2
  export default _default;
3
3
  //# sourceMappingURL=ExpoSystemUI.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoSystemUI.d.ts","sourceRoot":"","sources":["../src/ExpoSystemUI.ts"],"names":[],"mappings":";AAEA,wBAAqD"}
1
+ {"version":3,"file":"ExpoSystemUI.d.ts","sourceRoot":"","sources":["../src/ExpoSystemUI.ts"],"names":[],"mappings":";AACA,wBAAmD"}
@@ -1,3 +1,3 @@
1
- import { NativeModulesProxy } from 'expo-modules-core';
2
- export default NativeModulesProxy.ExpoSystemUI ?? {};
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ export default requireNativeModule('ExpoSystemUI');
3
3
  //# sourceMappingURL=ExpoSystemUI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoSystemUI.js","sourceRoot":"","sources":["../src/ExpoSystemUI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,eAAe,kBAAkB,CAAC,YAAY,IAAI,EAAE,CAAC","sourcesContent":["import { NativeModulesProxy } from 'expo-modules-core';\n\nexport default NativeModulesProxy.ExpoSystemUI ?? {};\n"]}
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"]}
@@ -2,6 +2,9 @@
2
2
  "name": "expo-system-ui",
3
3
  "platforms": ["ios", "android"],
4
4
  "ios": {
5
- "modulesClassNames": ["ExpoSystemUIModule"]
5
+ "modules": ["ExpoSystemUIModule"]
6
+ },
7
+ "android": {
8
+ "modules": ["expo.modules.systemui.SystemUIModule"]
6
9
  }
7
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-system-ui",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Interact with system UI elements",
5
5
  "main": "build/SystemUI.js",
6
6
  "types": "build/SystemUI.d.ts",
@@ -44,5 +44,5 @@
44
44
  "peerDependencies": {
45
45
  "expo": "*"
46
46
  },
47
- "gitHead": "eab2b09c735fb0fc2bf734a3f29a6593adba3838"
47
+ "gitHead": "ba80e8181b79d06e00a245653727f4eaeb80420e"
48
48
  }
@@ -1,6 +1,6 @@
1
1
  import { ExpoConfig } from 'expo/config';
2
2
  import { AndroidConfig, ConfigPlugin } from 'expo/config-plugins';
3
- export declare type Props = {
3
+ export type Props = {
4
4
  userInterfaceStyle?: ExpoConfig['userInterfaceStyle'];
5
5
  };
6
6
  export declare const withAndroidUserInterfaceStyle: ConfigPlugin<void>;
@@ -1,3 +1,2 @@
1
- import { NativeModulesProxy } from 'expo-modules-core';
2
-
3
- export default NativeModulesProxy.ExpoSystemUI ?? {};
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ export default requireNativeModule('ExpoSystemUI');