-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
209 additions
and
56 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
src/node_modules | ||
.vscode/ | ||
|
||
src/node_modules | ||
src/android/.settings/ | ||
src/android/.project | ||
src/android/app/.project | ||
src/android/app/.classpath | ||
src/android/app/.settings/ |
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
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
61 changes: 56 additions & 5 deletions
61
src/android/app/src/main/java/com/example/rnflutter/MainActivity.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,64 @@ | ||
package com.example.rnflutter; | ||
|
||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.provider.Settings; | ||
import android.widget.Toast; | ||
|
||
import io.flutter.app.FlutterActivity; | ||
import io.flutter.plugins.GeneratedPluginRegistrant; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler; | ||
import io.flutter.plugin.common.MethodChannel.Result; | ||
|
||
public class MainActivity extends FlutterActivity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
GeneratedPluginRegistrant.registerWith(this); | ||
} | ||
|
||
private final int OVERLAY_PERMISSION_REQ_CODE = 1; // Choose any value | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Only for development | ||
if (!Settings.canDrawOverlays(this)) { | ||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); | ||
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); | ||
} | ||
} | ||
|
||
new MethodChannel(getFlutterView(), "main_channel").setMethodCallHandler( | ||
new MethodCallHandler() { | ||
@Override | ||
public void onMethodCall(MethodCall call, Result result) { | ||
switch (call.method) { | ||
case "startRNActivity": | ||
result.success(null); | ||
Intent intent = new Intent(MainActivity.this, MyReactActivity.class); | ||
startActivity(intent); | ||
break; | ||
default: | ||
result.notImplemented(); | ||
} | ||
} | ||
} | ||
); | ||
|
||
GeneratedPluginRegistrant.registerWith(this); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { // Only for development | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
if (!Settings.canDrawOverlays(this)) { | ||
Toast.makeText(this, "SYSTEM_ALERT_WINDOW permission not granted", Toast.LENGTH_LONG).show(); | ||
// SYSTEM_ALERT_WINDOW permission not granted | ||
} | ||
} | ||
} | ||
//mReactInstanceManager.onActivityResult( this, requestCode, resultCode, data ); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/android/app/src/main/java/com/example/rnflutter/MyReactActivity.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.example.rnflutter; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.view.KeyEvent; | ||
|
||
import com.facebook.react.ReactInstanceManager; | ||
import com.facebook.react.ReactRootView; | ||
import com.facebook.react.common.LifecycleState; | ||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; | ||
import com.facebook.react.shell.MainReactPackage; | ||
|
||
public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler { | ||
|
||
private ReactRootView mReactRootView; | ||
private ReactInstanceManager mReactInstanceManager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
mReactRootView = new ReactRootView(this); | ||
mReactInstanceManager = ReactInstanceManager.builder() | ||
.setApplication(getApplication()) | ||
.setCurrentActivity(this) | ||
.setBundleAssetName("index.android.bundle") | ||
.setJSMainModulePath("index") | ||
.addPackage(new MainReactPackage()) | ||
.setUseDeveloperSupport(BuildConfig.DEBUG) | ||
.setInitialLifecycleState(LifecycleState.RESUMED) | ||
.build(); | ||
// The string here (e.g. "MyReactNativeApp") has to match | ||
// the string in AppRegistry.registerComponent() in index.js | ||
mReactRootView.startReactApplication(mReactInstanceManager, "RNFlutter", null); | ||
|
||
setContentView(mReactRootView); | ||
} | ||
|
||
@Override | ||
public void invokeDefaultOnBackPressed() { | ||
super.onBackPressed(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
|
||
if (mReactInstanceManager != null) { | ||
mReactInstanceManager.onHostPause(this); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
|
||
if (mReactInstanceManager != null) { | ||
mReactInstanceManager.onHostResume(this, this); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
|
||
if (mReactInstanceManager != null) { | ||
mReactInstanceManager.onHostDestroy(this); | ||
} | ||
if (mReactRootView != null) { | ||
mReactRootView.unmountReactApplication(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
if (mReactInstanceManager != null) { | ||
mReactInstanceManager.onBackPressed(); | ||
} else { | ||
super.onBackPressed(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onKeyUp(int keyCode, KeyEvent event) { | ||
if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) { | ||
mReactInstanceManager.showDevOptionsDialog(); | ||
return true; | ||
} | ||
return super.onKeyUp(keyCode, event); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from "react"; | ||
import {AppRegistry, StyleSheet, Text, View} from "react-native"; | ||
|
||
class RNFlutter extends React.Component { | ||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text style={styles.hello}>Hello from React Native and Flutter!</Text> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
var styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: "center", | ||
}, | ||
hello: { | ||
fontSize: 20, | ||
textAlign: "center", | ||
margin: 10, | ||
}, | ||
}); | ||
|
||
AppRegistry.registerComponent("RNFlutter", () => RNFlutter); |
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