Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unstable_reactLegacyComponent to cli-platform-android #1849

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type AndroidProjectParams = {
manifestPath?: string;
packageName?: string;
dependencyConfiguration?: string;
unstable_reactLegacyComponentNames?: string[] | null;
};
```

Expand Down Expand Up @@ -100,6 +101,18 @@ See [`dependency.platforms.android.packageName`](dependencies.md#platformsandroi

See [`dependency.platforms.android.configuration`](dependencies.md#platformsandroiddependencyconfiguration)

#### project.android.unstable_reactLegacyComponentNames

> Note: Only applicable when new architecture is turned on.

Please note that this is part of the **Unstable Fabric Interop Layer**, and might be subject to breaking change in the future,
hence the `unstable_` prefix.

An array with a list of Legacy Component Name that you want to be registered with the Fabric Interop Layer.
This will allow you to use on the New Architecture, libreries that are legacy and haven't been migrated yet.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This will allow you to use on the New Architecture, libreries that are legacy and haven't been migrated yet.
This will allow you to use on the New Architecture, libraries that are legacy and haven't been migrated yet.

;)


The list should contain the name of the components, as they're registered in the ViewManagers (i.e. just `"Button"`).

### platforms

A object with platforms defined inside a project. You can check the format and options available [`here`](platforms.md#platform-interface)
Expand Down
4 changes: 4 additions & 0 deletions packages/cli-config/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export const projectConfig = t
manifestPath: t.string(),
packageName: t.string(),
dependencyConfiguration: t.string(),
unstable_reactLegacyComponentNames: t
.array()
.items(t.string())
.default([]),
Comment on lines +163 to +166
Copy link
Contributor

@cipolleschi cipolleschi Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: for iOS, we just need these same lines in the iOS project above (Line 149).

The CLI doesn't have to do anything else for iOS, we just need the same key structure.

I can do it in a separate PR, if you prefer.

})
.default({}),
})
Expand Down
26 changes: 23 additions & 3 deletions packages/cli-platform-android/native_modules.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,16 @@ def rncliCppTemplate = """/**
namespace facebook {
namespace react {

{{ rncliReactLegacyComponentNames }}

std::shared_ptr<TurboModule> rncli_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
{{ rncliCppModuleProviders }}
return nullptr;
}

void rncli_registerProviders(std::shared_ptr<ComponentDescriptorProviderRegistry const> providerRegistry) {
{{ rncliCppComponentDescriptors }}
{{ rncliReactLegacyComponentDescriptors }}
return;
}

Expand Down Expand Up @@ -138,6 +141,7 @@ class ReactNativeModules {
private String packageName
private File root
private ArrayList<HashMap<String, String>> reactNativeModules
private ArrayList<String> unstable_reactLegacyComponentNames
private HashMap<String, ArrayList> reactNativeModulesBuildVariants

private static String LOG_PREFIX = ":ReactNative:"
Expand All @@ -146,10 +150,11 @@ class ReactNativeModules {
this.logger = logger
this.root = root

def (nativeModules, reactNativeModulesBuildVariants, packageName) = this.getReactNativeConfig()
def (nativeModules, reactNativeModulesBuildVariants, androidProject) = this.getReactNativeConfig()
this.reactNativeModules = nativeModules
this.reactNativeModulesBuildVariants = reactNativeModulesBuildVariants
this.packageName = packageName
this.packageName = androidProject["packageName"]
this.unstable_reactLegacyComponentNames = androidProject["unstable_reactLegacyComponentNames"]
}

/**
Expand Down Expand Up @@ -287,9 +292,12 @@ class ReactNativeModules {

void generateRncliCpp(File outputDir, String generatedFileName, String generatedFileContentsTemplate) {
ArrayList<HashMap<String, String>> packages = this.reactNativeModules
ArrayList<String> unstable_reactLegacyComponentNames = this.unstable_reactLegacyComponentNames
String rncliCppIncludes = ""
String rncliCppModuleProviders = ""
String rncliCppComponentDescriptors = ""
String rncliReactLegacyComponentDescriptors = ""
String rncliReactLegacyComponentNames = ""
String codegenComponentDescriptorsHeaderFile = "ComponentDescriptors.h"
String codegenReactComponentsDir = "react/renderer/components"

Expand Down Expand Up @@ -321,10 +329,22 @@ class ReactNativeModules {
}.join("\n")
}

rncliReactLegacyComponentDescriptors = unstable_reactLegacyComponentNames.collect {
" providerRegistry->add(concreteComponentDescriptorProvider<UnstableLegacyViewManagerInteropComponentDescriptor<${it}>>());"
}.join("\n")
rncliReactLegacyComponentNames = unstable_reactLegacyComponentNames.collect {
"extern const char ${it}[] = \"${it}\";"
}.join("\n")
if (unstable_reactLegacyComponentNames && unstable_reactLegacyComponentNames.size() > 0) {
rncliCppIncludes += "\n#include <react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerInteropComponentDescriptor.h>"
}

String generatedFileContents = generatedFileContentsTemplate
.replace("{{ rncliCppIncludes }}", rncliCppIncludes)
.replace("{{ rncliCppModuleProviders }}", rncliCppModuleProviders)
.replace("{{ rncliCppComponentDescriptors }}", rncliCppComponentDescriptors)
.replace("{{ rncliReactLegacyComponentDescriptors }}", rncliReactLegacyComponentDescriptors)
.replace("{{ rncliReactLegacyComponentNames }}", rncliReactLegacyComponentNames)

outputDir.mkdirs()
final FileTreeBuilder treeBuilder = new FileTreeBuilder(outputDir)
Expand Down Expand Up @@ -452,7 +472,7 @@ class ReactNativeModules {
}
}

return [reactNativeModules, reactNativeModulesBuildVariants, json["project"]["android"]["packageName"]];
return [reactNativeModules, reactNativeModulesBuildVariants, json["project"]["android"]];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Object {
"dependencyConfiguration": undefined,
"packageName": "com.some.example",
"sourceDir": "/flat/android",
"unstable_reactLegacyComponentNames": undefined,
}
`;

Expand All @@ -15,6 +16,7 @@ Object {
"dependencyConfiguration": undefined,
"packageName": "com.some.example",
"sourceDir": "/multiple/android",
"unstable_reactLegacyComponentNames": undefined,
}
`;

Expand All @@ -24,5 +26,6 @@ Object {
"dependencyConfiguration": undefined,
"packageName": "com.some.example",
"sourceDir": "/nested/android",
"unstable_reactLegacyComponentNames": undefined,
}
`;
2 changes: 2 additions & 0 deletions packages/cli-platform-android/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export function projectConfig(
appName,
packageName,
dependencyConfiguration: userConfig.dependencyConfiguration,
unstable_reactLegacyComponentNames:
userConfig.unstable_reactLegacyComponentNames,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/cli-types/src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface AndroidProjectConfig {
appName: string;
packageName: string;
dependencyConfiguration?: string;
unstable_reactLegacyComponentNames?: string[] | null;
}

export type AndroidProjectParams = {
Expand All @@ -11,6 +12,7 @@ export type AndroidProjectParams = {
manifestPath?: string;
packageName?: string;
dependencyConfiguration?: string;
unstable_reactLegacyComponentNames?: string[] | null;
};

export type AndroidDependencyConfig = {
Expand Down