Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I use static layout (native UI) in react native's native android implementation?

I am writing a react native application and I want to use some of the static layouts (for Android) I have from my old application.

I looked at https://facebook.github.io/react-native/docs/native-components-ios.html and wrote a few classes (MyViewManager.java and MyView.java).

I want to be able to use the static layouts I have for MyView.java.

I went through the facebook's react native code on github.

I could not find an appropriate method like setContentView(R.layout.myview). I was wondering if anybody tried this and this will work.

Can someone please help me with this problem?

like image 219
user4122421 Avatar asked Aug 11 '16 21:08

user4122421


1 Answers

You can try out something like

The layout inflater will inflate given xml file and put it as a child of this(second argument in inflate), which is MyLayoutView.

See the definition of inflate and change arguments as per customization required.

public class MyManyViewsManager extends ViewGroupManager<MyLayoutView> {

}

class MyLayoutView extends FrameLayout {

  init() {
        rootItem = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.xmlfilename, this, true);
  }

}
like image 167
jay shah Avatar answered Oct 25 '22 04:10

jay shah