Skip to content

Commit 1970c98

Browse files
committed
feat: create kotlin part
1 parent 3676c71 commit 1970c98

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.<%- project.package %>
2+
3+
import com.facebook.react.bridge.ReactApplicationContext
4+
import com.facebook.react.bridge.ReactMethod
5+
import com.facebook.react.bridge.Promise
6+
7+
class <%- project.name -%>Module internal constructor(context: ReactApplicationContext) :
8+
<%- project.name -%>Spec(context) {
9+
10+
override fun getName(): String {
11+
return NAME
12+
}
13+
14+
// Example method
15+
// See https://reactnative.dev/docs/native-modules-android
16+
@ReactMethod
17+
override fun multiply(a: Double, b: Double, promise: Promise) {
18+
promise.resolve(a * b)
19+
}
20+
21+
companion object {
22+
const val NAME = "<%- project.name -%>"
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.<%- project.package %>
2+
3+
import com.facebook.react.BaseReactPackage
4+
import com.facebook.react.bridge.ReactApplicationContext
5+
import com.facebook.react.bridge.NativeModule
6+
import com.facebook.react.module.model.ReactModuleInfoProvider
7+
import com.facebook.react.module.model.ReactModuleInfo
8+
import com.facebook.react.uimanager.ViewManager
9+
import java.util.HashMap
10+
11+
class <%- project.name -%>Package : BaseReactPackage() {
12+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
13+
return if (name == <%- project.name -%>Module.NAME) {
14+
<%- project.name -%>Module(reactContext)
15+
} else {
16+
null
17+
}
18+
}
19+
20+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
21+
return ReactModuleInfoProvider {
22+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
23+
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
24+
moduleInfos[<%- project.name -%>Module.NAME] = ReactModuleInfo(
25+
<%- project.name -%>Module.NAME,
26+
<%- project.name -%>Module.NAME,
27+
false, // canOverrideExistingModule
28+
false, // needsEagerInit
29+
true, // hasConstants
30+
false, // isCxxModule
31+
isTurboModule // isTurboModule
32+
)
33+
moduleInfos
34+
}
35+
}
36+
37+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
38+
return mutableListOf(<%- project.name -%>ViewManager());
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.<%- project.package %>
2+
3+
import android.content.Context
4+
import android.util.AttributeSet
5+
import android.view.View
6+
7+
class <%- project.name -%>View : View {
8+
constructor(context: Context?) : super(context)
9+
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
10+
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
11+
context,
12+
attrs,
13+
defStyleAttr
14+
)
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.<%- project.package %>
2+
3+
import android.graphics.Color
4+
import com.facebook.react.module.annotations.ReactModule
5+
import com.facebook.react.bridge.ReactApplicationContext
6+
import com.facebook.react.uimanager.ThemedReactContext
7+
import com.facebook.react.uimanager.annotations.ReactProp
8+
9+
@ReactModule(name = <%- project.name -%>ViewManager.NAME)
10+
class <%- project.name -%>ViewManager :
11+
<%- project.name -%>ViewManagerSpec<<%- project.name -%>View>() {
12+
override fun getName(): String {
13+
return NAME
14+
}
15+
16+
public override fun createViewInstance(context: ThemedReactContext): <%- project.name -%>View {
17+
return <%- project.name -%>View(context)
18+
}
19+
20+
@ReactProp(name = "color")
21+
override fun setColor(view: <%- project.name -%>View?, color: String?) {
22+
view?.setBackgroundColor(Color.parseColor(color))
23+
}
24+
25+
companion object {
26+
const val NAME = "<%- project.name -%>View"
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.<%- project.package %>
2+
3+
import com.facebook.react.bridge.ReactApplicationContext
4+
5+
abstract class <%- project.name -%>Spec internal constructor(context: ReactApplicationContext) :
6+
Native<%- project.name -%>Spec(context) {
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.<%- project.package %>
2+
3+
import android.view.View
4+
5+
import com.facebook.react.bridge.ReactApplicationContext
6+
import com.facebook.react.uimanager.SimpleViewManager
7+
import com.facebook.react.uimanager.ViewManagerDelegate
8+
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerDelegate
9+
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerInterface
10+
11+
abstract class <%- project.name -%>ViewManagerSpec<T : View> : SimpleViewManager<T>(), <%- project.name -%>ViewManagerInterface<T> {
12+
private val mDelegate: ViewManagerDelegate<T>
13+
14+
init {
15+
mDelegate = <%- project.name -%>ViewManagerDelegate(this)
16+
}
17+
18+
override fun getDelegate(): ViewManagerDelegate<T>? {
19+
return mDelegate
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.<%- project.package %>
2+
3+
import com.facebook.react.bridge.ReactApplicationContext
4+
import com.facebook.react.bridge.ReactContextBaseJavaModule
5+
import com.facebook.react.bridge.Promise
6+
7+
abstract class <%- project.name -%>Spec internal constructor(context: ReactApplicationContext) :
8+
ReactContextBaseJavaModule(context) {
9+
10+
abstract fun multiply(a: Double, b: Double, promise: Promise)
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.<%- project.package %>
2+
3+
import android.view.View
4+
import com.facebook.react.bridge.ReactApplicationContext
5+
import com.facebook.react.uimanager.SimpleViewManager
6+
7+
abstract class <%- project.name -%>ViewManagerSpec<T : View> : SimpleViewManager<T>() {
8+
abstract fun setColor(view: T?, value: String?)
9+
}

0 commit comments

Comments
 (0)