forked from Ivasoft/mattermost-mobile
[Gekidou] Fix & small refactor to the app entry logic and WS reconnection (#5937)
* Fix & small refactor to the app entry logic and WS reconnection * Remove not needed log in MainActivity * Replace async forEach with for await * extract getClient to its own block * replace double filter with reduce * fix select channel on WS reconnect and user no longer belongs to current team * feedback review on WS users actions * Add windowFocusChanged for Android only * on WS reconnection set team & channel if not member of current team * reduce suggestion * feedback review
This commit is contained in:
@@ -2,9 +2,14 @@ package com.mattermost.rnbeta;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.reactnativenavigation.NavigationActivity;
|
||||
import com.github.emilioicai.hwkeyboardevent.HWKeyboardEventModule;
|
||||
|
||||
@@ -29,6 +34,18 @@ public class MainActivity extends NavigationActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
// This can be removed once https://github.com/facebook/react-native/issues/32628 is solved
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
MattermostManagedModule instance = MattermostManagedModule.getInstance();
|
||||
if (instance != null) {
|
||||
WritableMap data = Arguments.createMap();
|
||||
data.putString("appState", hasFocus ? "active" : "background");
|
||||
instance.sendEvent("windowFocusChanged", data);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
https://mattermost.atlassian.net/browse/MM-10601
|
||||
Required by react-native-hw-keyboard-event
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mattermost.rnbeta;
|
||||
import android.app.Activity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
@@ -10,19 +11,24 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
|
||||
public class MattermostManagedModule extends ReactContextBaseJavaModule {
|
||||
private static MattermostManagedModule instance;
|
||||
private ReactApplicationContext reactContext;
|
||||
|
||||
private static final String TAG = MattermostManagedModule.class.getSimpleName();
|
||||
|
||||
private MattermostManagedModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
this.reactContext = reactContext;
|
||||
}
|
||||
|
||||
public static MattermostManagedModule getInstance(ReactApplicationContext reactContext) {
|
||||
if (instance == null) {
|
||||
instance = new MattermostManagedModule(reactContext);
|
||||
} else {
|
||||
instance.reactContext = reactContext;
|
||||
}
|
||||
|
||||
return instance;
|
||||
@@ -32,6 +38,13 @@ public class MattermostManagedModule extends ReactContextBaseJavaModule {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void sendEvent(String eventName,
|
||||
@Nullable WritableMap params) {
|
||||
this.reactContext
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
||||
.emit(eventName, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String getName() {
|
||||
|
||||
Reference in New Issue
Block a user