[Android] Implement DefaultHardwareBackBtnHandler

If the JS side chooses to not handle the back button press call
'super.onBackPressed()' to close the app.
This commit is contained in:
paweldomas 2017-09-18 10:53:10 -05:00 committed by Lyubo Marinov
parent 720ae18194
commit 35dab19b30
2 changed files with 25 additions and 5 deletions

View File

@ -26,6 +26,8 @@ import android.support.v7.app.AppCompatActivity;
import java.net.URL;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
/**
* Base Activity for applications integrating Jitsi Meet at a higher level. It
* contains all the required wiring between the <tt>JKConferenceView</tt> and
@ -37,7 +39,10 @@ import java.net.URL;
* hooked to the React Native subsystem via proxy calls through the
* <tt>JKConferenceView</tt> static methods.
*/
public class JitsiMeetActivity extends AppCompatActivity {
public class JitsiMeetActivity
extends AppCompatActivity
implements DefaultHardwareBackBtnHandler {
/**
* The request code identifying requests for the permission to draw on top
* of other apps. The value must be 16-bit and is arbitrarily chosen here.
@ -128,6 +133,15 @@ public class JitsiMeetActivity extends AppCompatActivity {
}
}
/**
* This method is called if the JS part does not handle the physical back
* button press.
*/
@Override
public void invokeDefaultOnBackPressed() {
super.onBackPressed();
}
/**
* {@inheritDoc}
*/
@ -201,7 +215,7 @@ public class JitsiMeetActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
JitsiMeetView.onHostResume(this);
JitsiMeetView.onHostResume(this, this);
}
/**

View File

@ -27,10 +27,12 @@ import android.support.annotation.Nullable;
import android.widget.FrameLayout;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactInstanceManagerBuilder;
import com.facebook.react.ReactRootView;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import java.net.URL;
import java.util.Arrays;
@ -184,10 +186,14 @@ public class JitsiMeetView extends FrameLayout {
* <tt>Activity.onResume</tt> so we can do the required internal processing.
*
* @param activity - <tt>Activity</tt> being resumed.
* @param backHandler - a <tt>DefaultHardwareBackBtnHandler</tt> which
* will handle the back button press in case there's nothing to handle on
* the JS side.
*/
public static void onHostResume(Activity activity) {
public static void onHostResume(Activity activity,
DefaultHardwareBackBtnHandler backHandler) {
if (reactInstanceManager != null) {
reactInstanceManager.onHostResume(activity, null);
reactInstanceManager.onHostResume(activity, backHandler);
}
}