Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3384786
D5934.id19674.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D5934.id19674.diff
View Options
diff --git a/native/android/app/build.gradle b/native/android/app/build.gradle
--- a/native/android/app/build.gradle
+++ b/native/android/app/build.gradle
@@ -671,9 +671,6 @@
implementation project(':reactnativekeyboardinput')
implementation "androidx.multidex:multidex:2.0.1"
- implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"
- implementation "androidx.lifecycle:lifecycle-process:2.2.0"
-
implementation 'com.facebook.fresco:fresco:2.2.0'
implementation 'com.facebook.fresco:animated-gif:2.2.0'
implementation 'com.facebook.fresco:animated-webp:2.2.0'
diff --git a/native/android/app/src/main/java/app/comm/android/AndroidLifecycleModule.java b/native/android/app/src/main/java/app/comm/android/AndroidLifecycleModule.java
deleted file mode 100644
--- a/native/android/app/src/main/java/app/comm/android/AndroidLifecycleModule.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package app.comm.android;
-
-import androidx.lifecycle.Lifecycle;
-import androidx.lifecycle.LifecycleEventObserver;
-import androidx.lifecycle.ProcessLifecycleOwner;
-import com.facebook.react.bridge.Arguments;
-import com.facebook.react.bridge.Callback;
-import com.facebook.react.bridge.ReactApplicationContext;
-import com.facebook.react.bridge.ReactContextBaseJavaModule;
-import com.facebook.react.bridge.ReactMethod;
-import com.facebook.react.bridge.UiThreadUtil;
-import com.facebook.react.bridge.WritableMap;
-import com.facebook.react.module.annotations.ReactModule;
-import com.facebook.react.modules.core.DeviceEventManagerModule;
-import java.util.HashMap;
-import java.util.Map;
-
-@ReactModule(name = AndroidLifecycleModule.NAME)
-public class AndroidLifecycleModule extends ReactContextBaseJavaModule {
-
- public static final String NAME = "AndroidLifecycle";
-
- public static final String ANDROID_LIFECYCLE_ACTIVE = "active";
- public static final String ANDROID_LIFECYCLE_BACKGROUND = "background";
-
- private static final String INITIAL_STATUS_KEY = "initialStatus";
- private static final String STATUS_KEY = "status";
-
- private boolean isInitialized = false;
-
- private String currentState;
-
- public AndroidLifecycleModule(ReactApplicationContext reactContext) {
- super(reactContext);
-
- final Lifecycle lifecycle = ProcessLifecycleOwner.get().getLifecycle();
- this.currentState = lifecycle.getCurrentState() == Lifecycle.State.RESUMED
- ? ANDROID_LIFECYCLE_ACTIVE
- : ANDROID_LIFECYCLE_BACKGROUND;
-
- UiThreadUtil.runOnUiThread(() -> {
- lifecycle.addObserver((LifecycleEventObserver)(source, event) -> {
- final String name = event.toString();
- if (name != "ON_START" && name != "ON_STOP") {
- return;
- }
- if (!this.isInitialized) {
- return;
- }
- this.currentState = name == "ON_START" ? ANDROID_LIFECYCLE_ACTIVE
- : ANDROID_LIFECYCLE_BACKGROUND;
- reactContext
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("LIFECYCLE_CHANGE", this.createEventMap());
- });
- });
- }
-
- @Override
- public String getName() {
- return NAME;
- }
-
- @Override
- public void initialize() {
- super.initialize();
- this.isInitialized = true;
- }
-
- @Override
- public Map<String, Object> getConstants() {
- final Map<String, Object> constants = new HashMap<>();
- constants.put(INITIAL_STATUS_KEY, this.currentState);
- return constants;
- }
-
- private WritableMap createEventMap() {
- WritableMap appState = Arguments.createMap();
- appState.putString(STATUS_KEY, this.currentState);
- return appState;
- }
-
- @ReactMethod
- public void getCurrentLifecycleStatus(Callback success, Callback error) {
- success.invoke(createEventMap());
- }
-}
diff --git a/native/android/app/src/main/java/app/comm/android/CommPackage.java b/native/android/app/src/main/java/app/comm/android/CommPackage.java
deleted file mode 100644
--- a/native/android/app/src/main/java/app/comm/android/CommPackage.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package app.comm.android;
-
-import com.facebook.react.ReactPackage;
-import com.facebook.react.bridge.NativeModule;
-import com.facebook.react.bridge.ReactApplicationContext;
-import com.facebook.react.uimanager.ViewManager;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class CommPackage implements ReactPackage {
-
- @Override
- public List<ViewManager>
- createViewManagers(ReactApplicationContext reactContext) {
- return Collections.emptyList();
- }
-
- @Override
- public List<NativeModule>
- createNativeModules(ReactApplicationContext reactContext) {
- List<NativeModule> modules = new ArrayList<>();
- modules.add(new AndroidLifecycleModule(reactContext));
- return modules;
- }
-}
diff --git a/native/android/app/src/main/java/app/comm/android/MainApplication.java b/native/android/app/src/main/java/app/comm/android/MainApplication.java
--- a/native/android/app/src/main/java/app/comm/android/MainApplication.java
+++ b/native/android/app/src/main/java/app/comm/android/MainApplication.java
@@ -44,7 +44,6 @@
packages.add(new RNFirebaseMessagingPackage());
packages.add(new RNFirebaseNotificationsPackage());
packages.add(new KeyboardInputPackage(this.getApplication()));
- packages.add(new CommPackage());
return packages;
}
diff --git a/native/lifecycle/lifecycle-event-emitter.js b/native/lifecycle/lifecycle-event-emitter.js
deleted file mode 100644
--- a/native/lifecycle/lifecycle-event-emitter.js
+++ /dev/null
@@ -1,60 +0,0 @@
-// @flow
-
-import invariant from 'invariant';
-import { Platform } from 'react-native';
-import NativeEventEmitter from 'react-native/Libraries/EventEmitter/NativeEventEmitter';
-import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
-import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
-
-import type { LifecycleState } from 'lib/types/lifecycle-state-types';
-
-import type { EventSubscription } from '../types/react-native';
-
-interface Spec extends TurboModule {
- +getConstants: () => {
- initialStatus: string,
- };
- +addListener: (eventName: string) => void;
- +removeListeners: (count: number) => void;
-}
-const AndroidLifecycle = (TurboModuleRegistry.getEnforcing<Spec>(
- 'AndroidLifecycle',
-): Spec);
-
-type LifecycleEventEmitterArgs = {
- +LIFECYCLE_CHANGE: [{ +status: ?LifecycleState }],
-};
-class LifecycleEventEmitter extends NativeEventEmitter<LifecycleEventEmitterArgs> {
- currentLifecycleStatus: ?string;
-
- constructor() {
- super(AndroidLifecycle);
- this.currentLifecycleStatus = AndroidLifecycle.getConstants().initialStatus;
- this.addLifecycleListener(state => {
- this.currentLifecycleStatus = state;
- });
- }
-
- addLifecycleListener: (
- listener: (state: ?LifecycleState) => void,
- ) => EventSubscription = listener => {
- return this.addListener('LIFECYCLE_CHANGE', event => {
- listener(event.status);
- });
- };
-}
-
-let lifecycleEventEmitter;
-function getLifecycleEventEmitter(): LifecycleEventEmitter {
- if (lifecycleEventEmitter) {
- return lifecycleEventEmitter;
- }
- invariant(
- Platform.OS === 'android',
- 'LifecycleEventEmitter only works on Android',
- );
- lifecycleEventEmitter = new LifecycleEventEmitter();
- return lifecycleEventEmitter;
-}
-
-export { getLifecycleEventEmitter };
diff --git a/native/lifecycle/lifecycle.js b/native/lifecycle/lifecycle.js
--- a/native/lifecycle/lifecycle.js
+++ b/native/lifecycle/lifecycle.js
@@ -5,13 +5,20 @@
import { type LifecycleState } from 'lib/types/lifecycle-state-types';
import type { EventSubscription } from '../types/react-native';
-import { getLifecycleEventEmitter } from './lifecycle-event-emitter';
+import { addAndroidLifecycleListener, initialStatus } from './lifecycle-module';
+
+let currentLifecycleStatus = initialStatus;
+if (Platform.OS === 'android') {
+ addAndroidLifecycleListener(state => {
+ currentLifecycleStatus = state;
+ });
+}
function addLifecycleListener(
listener: (state: ?LifecycleState) => void,
): EventSubscription {
if (Platform.OS === 'android') {
- return getLifecycleEventEmitter().addLifecycleListener(listener);
+ return addAndroidLifecycleListener(listener);
}
return NativeAppState.addEventListener('change', listener);
@@ -19,7 +26,7 @@
function getCurrentLifecycleState(): ?string {
return Platform.OS === 'android'
- ? getLifecycleEventEmitter().currentLifecycleStatus
+ ? currentLifecycleStatus
: NativeAppState.currentState;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 10:31 PM (13 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2598370
Default Alt Text
D5934.id19674.diff (8 KB)
Attached To
Mode
D5934: [native] [33/40] RN 0.70: Replace old AndroidLifecycleModule with new Expo one
Attached
Detach File
Event Timeline
Log In to Comment