Skip to content

Commit

Permalink
[android] backport fix for sdk47 to versioned code (#20062)
Browse files Browse the repository at this point in the history
# Why

backport fix for sdk47 to versioned code

# How

- backport #19920
- backport #20037
- backport #20063

(cherry picked from commit e8fa33d)
  • Loading branch information
Kudo committed Nov 22, 2022
1 parent c0225c6 commit 7dd95e1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ private synchronized NativeModulesProxy getOrCreateNativeModulesProxy(
) {
if (mModulesProxy != null && mModulesProxy.getReactContext() != reactContext) {
mModulesProxy = null;
mWrapperDelegateHolders = null;
}
if (mModulesProxy == null) {
ModuleRegistry registry = moduleRegistry != null ? moduleRegistry : mModuleRegistryProvider.get(reactContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ open class ObjectDefinitionBuilder {
internal var properties = mutableMapOf<String, PropertyComponentBuilder>()

fun buildObject(): ObjectDefinitionData {
// Register stub functions to bypass react-native `NativeEventEmitter` warnings
// WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
// WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
eventsDefinition?.run {
if (!containsFunction("addListener")) {
Function("addListener") { _: String -> { } }
}
if (!containsFunction("removeListeners")) {
Function("removeListeners") { _: Int -> { } }
}
}

return ObjectDefinitionData(
constantsProvider,
syncFunctions,
Expand All @@ -52,6 +64,12 @@ open class ObjectDefinitionBuilder {
)
}

private fun containsFunction(functionName: String): Boolean {
return syncFunctions.containsKey(functionName) ||
asyncFunctions.containsKey(functionName) ||
functionBuilders.containsKey(functionName)
}

/**
* Definition function setting the module's constants to export.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ object TypeConverterProviderImpl : TypeConverterProvider {
isOptional, ExpectedType(CppType.BOOLEAN)
) { it.asBoolean() }

return mapOf(
val converters = mapOf(
Int::class.createType(nullable = isOptional) to intTypeConverter,
java.lang.Integer::class.createType(nullable = isOptional) to intTypeConverter,

Expand Down Expand Up @@ -229,9 +229,16 @@ object TypeConverterProviderImpl : TypeConverterProvider {
URI::class.createType(nullable = isOptional) to JavaURITypeConverter(isOptional),

File::class.createType(nullable = isOptional) to FileTypeConverter(isOptional),
Path::class.createType(nullable = isOptional) to PathTypeConverter(isOptional),

Any::class.createType(nullable = isOptional) to AnyTypeConverter(isOptional),
)

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
return converters + mapOf(
Path::class.createType(nullable = isOptional) to PathTypeConverter(isOptional),
)
}

return converters
}
}

0 comments on commit 7dd95e1

Please sign in to comment.