there is currently an old android project written in the native java language, and now you want to integrate react native, to develop new requirements in js.
at present, react native, has been successfully integrated into the project, and if the activity of app startup is the corresponding activity of this react native, it will start normally and display normally.
but if you add a button, to the old project and jump to the activity written by react native in the way of startActivity, there is no error, the page is empty and has no effect.
androidbuttonreact native:
mBtnForward.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "");
Intent intent = new Intent();
intent.setClass(StartActivity.this, BaseReactActivity.class);
startActivity(intent);
}
});
AndroidManifest.xml
<activity
android:name=".activity.BaseReactActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
</activity>
BaseReactActivity
package com.sitech.ac.activity;
import com.facebook.react.ReactActivity;
public class BaseReactActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "HelloWorld";
}
}
App.js
import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
Button
} from "react-native";
const instructions = Platform.select({
ios: "Press Cmd+R to reload,\n" +
"Cmd+D or shake for dev menu",
android: "Double tap R on your keyboard to reload,\n" +
"Shake or press menu button for dev menu",
});
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<Button
title=""
color="red"
accessibilityLabel="Learn more about this purple button"
/>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "yellow",
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10,
},
instructions: {
textAlign: "center",
color: "-sharp333333",
marginBottom: 5,
},
});