Created
May 30, 2018 02:31
-
-
Save andatta/1266b2b887f3e248e19e2c346a43710b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class SampleReactActivity extends Activity implements DefaultHardwareBackBtnHandler, | |
PermissionAwareActivity { | |
private final SampleReactActivityDelegate mDelegate; | |
protected SampleReactActivity() { | |
mDelegate = createReactActivityDelegate(); | |
} | |
/** | |
* Returns the name of the main component registered from JavaScript. | |
* This is used to schedule rendering of the component. | |
* e.g. "MoviesApp" | |
*/ | |
protected @Nullable | |
String getMainComponentName() { | |
return null; | |
} | |
/** | |
* Called at construction time, override if you have a custom delegate implementation. | |
*/ | |
protected SampleReactActivityDelegate createReactActivityDelegate() { | |
return new Sample | |
ReactActivityDelegate(this, getMainComponentName()); | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mDelegate.onCreate(savedInstanceState); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
mDelegate.onPause(); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
mDelegate.onResume(); | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
mDelegate.onDestroy(); | |
} | |
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
mDelegate.onActivityResult(requestCode, resultCode, data); | |
} | |
@Override | |
public boolean onKeyUp(int keyCode, KeyEvent event) { | |
return mDelegate.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event); | |
} | |
@Override | |
public void onBackPressed() { | |
if (!mDelegate.onBackPressed()) { | |
super.onBackPressed(); | |
} | |
} | |
@Override | |
public void invokeDefaultOnBackPressed() { | |
super.onBackPressed(); | |
} | |
@Override | |
public void onNewIntent(Intent intent) { | |
if (!mDelegate.onNewIntent(intent)) { | |
super.onNewIntent(intent); | |
} | |
} | |
@Override | |
public void requestPermissions( | |
String[] permissions, | |
int requestCode, | |
PermissionListener listener) { | |
mDelegate.requestPermissions(permissions, requestCode, listener); | |
} | |
@Override | |
public void onRequestPermissionsResult( | |
int requestCode, | |
String[] permissions, | |
int[] grantResults) { | |
mDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
} | |
protected final ReactNativeHost getReactNativeHost() { | |
return mDelegate.getReactNativeHost(); | |
} | |
protected final ReactInstanceManager getReactInstanceManager() { | |
return mDelegate.getReactInstanceManager(); | |
} | |
protected final void loadApp(String appKey) { | |
mDelegate.loadApp(appKey); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment