Skip to content
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
5 changes: 5 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
Expand All @@ -48,6 +52,7 @@ android {
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}
lintOptions {
abortOnError false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

public class LaunchArgumentsModule extends ReactContextBaseJavaModule {

public static final String NAME = "LaunchArguments";

private static final long ACTIVITY_WAIT_INTERVAL = 100L;
private static final int ACTIVITY_WAIT_TRIES = 200;

Expand All @@ -32,7 +34,7 @@ public class LaunchArgumentsModule extends ReactContextBaseJavaModule {
@NonNull
@Override
public String getName() {
return "LaunchArguments";
return NAME;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
package com.reactnativelauncharguments;

import com.facebook.react.ReactPackage;
import com.facebook.react.BaseReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.TurboReactPackage;

import java.util.Collections;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

public class LaunchArgumentsPackage implements ReactPackage {

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class LaunchArgumentsPackage extends TurboReactPackage {

@Nullable
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
public NativeModule getModule(String name, @Nonnull ReactApplicationContext reactContext) {
if (name.equals(LaunchArgumentsModule.NAME)) {
return new LaunchArgumentsModule(reactContext);
} else {
return null;
}
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
final NativeModule nativeModule = new LaunchArgumentsModule(reactContext);
return Collections.singletonList(nativeModule);
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return () -> {
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
moduleInfos.put(
LaunchArgumentsModule.NAME,
new ReactModuleInfo(
LaunchArgumentsModule.NAME,
LaunchArgumentsModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
));
return moduleInfos;
};
}
}
8 changes: 8 additions & 0 deletions ios/LaunchArguments.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#import <React/RCTBridgeModule.h>

#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTTurboModule.h>
#import "RCTNativeLaunchArgumentsSpec.h"

@interface LaunchArguments : NSObject <NativeLaunchArgumentsSpec>
#else
@interface LaunchArguments : NSObject <RCTBridgeModule>
#endif

@end
16 changes: 16 additions & 0 deletions ios/LaunchArguments.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ @implementation LaunchArguments

RCT_EXPORT_MODULE()

#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeLaunchArgumentsSpecJSI>(params);
}
#endif

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
Expand Down Expand Up @@ -107,4 +115,12 @@ - (NSString *)cleanValue:(NSString *)arg
return [arg stringByReplacingOccurrencesOfString:@"-" withString:@""];
}

#ifdef RCT_NEW_ARCH_ENABLED
- (facebook::react::ModuleConstants<JS::NativeLaunchArguments::Constants>)getConstants {
return facebook::react::typedConstants<JS::NativeLaunchArguments::Constants>({
.value = facebook::react::toDynamic([self argsToDictionary])
});
}
#endif

@end
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@
"react": "^16.9.0",
"react-native": "^0.62.2",
"typescript": "^3.8.3"
},
"codegenConfig": {
"name": "RNLaunchArgumentsSpec",
"type": "modules",
"jsSrcsDir": "src"
}
}
15 changes: 12 additions & 3 deletions react-native-launch-arguments.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ Pod::Spec.new do |s|
s.platforms = { :ios => "9.0" }
s.source = { :git => "#{package["repository"]["baseUrl"]}.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,swift}"
s.source_files = "ios/**/*.{h,m,mm}"
s.requires_arc = true

s.dependency "React"
end
install_modules_dependencies(s)

if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/RCT-Folly\"",
"DEFINES_MODULE" => "YES",
"SWIFT_OBJC_INTERFACE_HEADER_NAME" => "$(SWIFT_MODULE_NAME)-Swift.h"
}

s.compiler_flags = '-DRCT_NEW_ARCH_ENABLED'
end
end
18 changes: 18 additions & 0 deletions react-native.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
dependency: {
platforms: {
android: {
sourceDir: '../android/src/main/java/com/reactnativelauncharguments',
packageImportPath: 'import com.reactnativelauncharguments.LaunchArgumentsPackage;',
componentDescriptors: null,
cmakeListsPath: null,
},
ios: {
libraryFolder: '../ios',
sharedLibraries: [],
project: 'LaunchArguments.xcodeproj',
podspecPath: '../react-native-launch-arguments.podspec',
},
},
},
};
10 changes: 10 additions & 0 deletions src/NativeLaunchArguments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';

export interface Spec extends TurboModule {
getConstants(): {
value: { [key: string]: string };
};
}

export default TurboModuleRegistry.getEnforcing<Spec>('LaunchArguments');
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const LINKING_ERROR =
"- You rebuilt the app after installing the package\n" +
"- You are not using Expo managed workflow\n";

const LaunchArgumentsModule = NativeModules.LaunchArguments
// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;

const LaunchArgumentsModule = isTurboModuleEnabled
? require('./NativeLaunchArguments').default
: NativeModules.LaunchArguments
? NativeModules.LaunchArguments
: new Proxy(
{},
Expand Down Expand Up @@ -35,7 +40,11 @@ export const LaunchArguments: LaunchArgumentsType = {

parsed = {};

const raw = LaunchArgumentsModule.value as RawMap;
const constants = isTurboModuleEnabled
? LaunchArgumentsModule.getConstants()
: LaunchArgumentsModule;

const raw = constants.value as RawMap;

for (const k in raw) {
const rawValue = raw[k];
Expand Down