I'm trying to make a native module with new architecture in React Native. but with layout xmls. It worked fine to make native module without xmls when I followed the RN's official documents, but there's no reference with layout files.
the code below is CenteredText.kt.
package com.rtncenteredtext;
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.Gravity
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
class CenteredText : ConstraintLayout {
constructor(context: Context) : super(context) {
configureComponent()
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
configureComponent()
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
configureComponent()
}
public fun init() : Unit {
inflate(context, R.layout.activity_main, this)
}
private fun configureComponent() {
}
}
module tree
│ package.json
│ rtn-centered-text.podspec
│
├─android
│ │ build.gradle
│ │
│ └─src
│ └─main
│ ├─java
│ │ └─com
│ │ └─rtncenteredtext
│ │ CenteredText.kt
│ │ CenteredTextManager.kt
│ │ CenteredTextPackage.kt
│ │
│ └─res
│ └─layout
│ acitivity_main.xml
│
├─ios
└─js
RTNCenteredTextNativeComponent.ts
The main problem is that it's not able to find activity_main.xml and the build failed message is like below:
e: file:///C:/steveloper/reactnative/test003/node_modules/rtn-centered-text/android/src/main/java/com/rtncenteredtext/CenteredText.kt:30:31 Unresolved reference: activity_main
is it possible to make a module with layout xmls?