Answer the question
In order to leave comments, you need to log in
React Native. Why is the Android component not rendering?
I want to add a component from Android to React Native. But it doesn't render and doesn't have dimensions. How can I fix this?
I used other people's guides and examples. Classes to connect the component:
CustomViewManager.java:
public class CustomViewManager extends SimpleViewManager<TextView> {
public static final String REACT_CLASS = "CustomView";
@Override
public String getName() {
return REACT_CLASS;
}
@Override
public TextView createViewInstance(ThemedReactContext context) {
TextView tv = new TextView(context);
tv.setText("Текст");
tv.setTextColor(Color.BLACK);
tv.setWidth(100);
tv.setHeight(100);
return tv;
}
}
public class CustomViewPackage implements ReactPackage {
@Override
public List<ViewManager>
createViewManagers(ReactApplicationContext reactContext) {
return Arrays.<ViewManager>asList(
new CustomViewManager()
);
}
@Override
public List<NativeModule>
createNativeModules(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new CustomViewPackage()
);
}
import React from 'react';
import {
requireNativeComponent
} from 'react-native';
module.exports = requireNativeComponent('CustomView');
export default class App extends Component {
render() {
return (
<View
style={ styles.container }
>
<CustomView/>
</View>
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question