I am creating an Android View Component to use in React Native. However, I noticed that some components are not visible in React Native. For example, I created a very simple TextView as an Android View Component to use in React Native, but it was not visible.
public class MyCustomView extends FrameLayout {
private TextView textView;
public MyCustomView(Context context) {
super(context);
textView = new TextView(context);
textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
addView(textView);
}
public void setText(String text) {
textView.setText(text);
}
}
const App = () => {
return (
<SafeAreaView>
<MyCustomView text="Hello, World!" />
</SafeAreaView>
);
};
While investigating the cause, I came across the following issue.
Adding Native UI component to React Native does nothing
However, once I added a style to the component, it became visible. While the issue is resolved, I don’t understand the reason behind it. Why doesn’t the component appear unless a style is applied?