-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
260 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...-legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule | ||
import com.facebook.react.bridge.ReactMethod | ||
import com.facebook.react.bridge.Promise | ||
|
||
class <%- project.name -%>Module(reactContext: ReactApplicationContext) : | ||
ReactContextBaseJavaModule(reactContext) { | ||
|
||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
// Example method | ||
// See https://reactnative.dev/docs/native-modules-android | ||
@ReactMethod | ||
fun multiply(a: Double, b: Double, promise: Promise) { | ||
promise.resolve(a * b) | ||
} | ||
|
||
companion object { | ||
const val NAME = "<%- project.name -%>" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.uimanager.ViewManager | ||
|
||
|
||
class <%- project.name -%>Package : ReactPackage { | ||
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> { | ||
return listOf(<%- project.name -%>Module(reactContext)) | ||
} | ||
|
||
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> { | ||
return emptyList() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...y-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReactMethod | ||
import com.facebook.react.bridge.Promise | ||
|
||
class <%- project.name -%>Module internal constructor(context: ReactApplicationContext) : | ||
<%- project.name -%>Spec(context) { | ||
|
||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
// Example method | ||
// See https://reactnative.dev/docs/native-modules-android | ||
@ReactMethod | ||
override fun multiply(a: Double, b: Double, promise: Promise) { | ||
promise.resolve(a * b) | ||
} | ||
|
||
companion object { | ||
const val NAME = "<%- project.name -%>" | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...-mixed/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
import com.facebook.react.module.model.ReactModuleInfo | ||
import java.util.HashMap | ||
|
||
class <%- project.name -%>Package : TurboReactPackage() { | ||
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { | ||
return if (name == <%- project.name -%>Module.NAME) { | ||
<%- project.name -%>Module(reactContext) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
return ReactModuleInfoProvider { | ||
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap() | ||
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED | ||
moduleInfos[<%- project.name -%>Module.NAME] = ReactModuleInfo( | ||
<%- project.name -%>Module.NAME, | ||
<%- project.name -%>Module.NAME, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
isTurboModule // isTurboModule | ||
) | ||
moduleInfos | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ive-library/templates/kotlin-library-mixed/android/src/newarch/{%- project.name %}Spec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
|
||
abstract class <%- project.name -%>Spec internal constructor(context: ReactApplicationContext) : | ||
Native<%- project.name -%>Spec(context) { | ||
} |
11 changes: 11 additions & 0 deletions
11
...ive-library/templates/kotlin-library-mixed/android/src/oldarch/{%- project.name %}Spec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule | ||
import com.facebook.react.bridge.Promise | ||
|
||
abstract class <%- project.name -%>Spec internal constructor(context: ReactApplicationContext) : | ||
ReactContextBaseJavaModule(context) { | ||
|
||
abstract fun multiply(a: Double, b: Double, promise: Promise) | ||
} |
23 changes: 23 additions & 0 deletions
23
...ary-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Module.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.annotations.ReactModule | ||
|
||
@ReactModule(name = <%- project.name -%>Module.NAME) | ||
class <%- project.name -%>Module(reactContext: ReactApplicationContext) : | ||
Native<%- project.name -%>Spec(reactContext) { | ||
|
||
override fun getName(): String { | ||
return NAME | ||
} | ||
|
||
// Example method | ||
// See https://reactnative.dev/docs/native-modules-android | ||
override fun multiply(a: Double, b: Double): Double { | ||
return a * b | ||
} | ||
|
||
companion object { | ||
const val NAME = "<%- project.name -%>" | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ry-new/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.model.ReactModuleInfo | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
import java.util.HashMap | ||
|
||
class <%- project.name -%>Package : TurboReactPackage() { | ||
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { | ||
return if (name == <%- project.name -%>Module.NAME) { | ||
<%- project.name -%>Module(reactContext) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
return ReactModuleInfoProvider { | ||
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap() | ||
moduleInfos[<%- project.name -%>Module.NAME] = ReactModuleInfo( | ||
<%- project.name -%>Module.NAME, | ||
<%- project.name -%>Module.NAME, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
true // isTurboModule | ||
) | ||
moduleInfos | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...legacy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}Package.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.<%- project.package %> | ||
|
||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.uimanager.ViewManager | ||
|
||
|
||
class <%- project.name -%>Package : ReactPackage { | ||
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> { | ||
return emptyList() | ||
} | ||
|
||
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> { | ||
return listOf(<%- project.name -%>ViewManager()) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...cy/android/src/main/java/com/{%- project.package_dir %}/{%- project.name %}ViewManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.<%- project.package %> | ||
|
||
import android.graphics.Color | ||
import android.view.View | ||
import com.facebook.react.uimanager.SimpleViewManager | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.uimanager.annotations.ReactProp | ||
|
||
class <%- project.name -%>ViewManager : SimpleViewManager<View>() { | ||
override fun getName() = "<%- project.name -%>View" | ||
|
||
override fun createViewInstance(reactContext: ThemedReactContext): View { | ||
return View(reactContext) | ||
} | ||
|
||
@ReactProp(name = "color") | ||
fun setColor(view: View, color: String) { | ||
view.setBackgroundColor(Color.parseColor(color)) | ||
} | ||
} |