Skip to content
Open
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
85 changes: 8 additions & 77 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
// android/build.gradle

// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
// original location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
// original location:
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
// This avoids unnecessary downloads and potential conflicts when the library is included as a
// module dependency in an application project.
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
if (project == rootProject) {
repositories {
google()
Expand All @@ -26,11 +15,6 @@ buildscript {
}
}

plugins {
id('com.android.library')
id('maven-publish')
}

def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_MIN_SDK_VERSION = 18
Expand All @@ -40,9 +24,15 @@ def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

apply plugin: 'com.android.library'
apply plugin: 'com.facebook.react'

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)

namespace "com.reactnativelauncharguments"

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
Expand All @@ -55,7 +45,6 @@ android {
}

repositories {
// ref: https://www.baeldung.com/maven-local-repository
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
Expand All @@ -66,68 +55,10 @@ repositories {
url "$rootDir/../node_modules/jsc-android/dist"
}
google()
mavenCentral()
}

dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

pom.project {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "com.reactnativelauncharguments"
description packageJson.description
url packageJson.repository.baseUrl

licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}

developers {
developer {
id packageJson.author.username
name packageJson.author.name
}
}
}
}

afterEvaluate { project ->
// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidSourcesJar(type: Jar) {
archiveClassifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}

android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
def javaCompileTask = variant.javaCompileProvider.get()

task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
from javaCompileTask.destinationDir
}
}

artifacts {
archives androidSourcesJar
}

publishing {
publications {
maven(MavenPublication) {
artifact androidSourcesJar
}
}
}
implementation 'com.facebook.react:react-native:+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@
import android.content.Intent;
import android.os.Bundle;

import com.facebook.fbreact.specs.NativeLaunchArgumentsSpec;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class LaunchArgumentsModule extends ReactContextBaseJavaModule {
public class LaunchArgumentsModule extends NativeLaunchArgumentsSpec {

private static final long ACTIVITY_WAIT_INTERVAL = 100L;
private static final int ACTIVITY_WAIT_TRIES = 200;
Expand All @@ -29,15 +24,8 @@ public class LaunchArgumentsModule extends ReactContextBaseJavaModule {
super(context);
}

@NonNull
@Override
public String getName() {
return "LaunchArguments";
}

@Nullable
@Override
public Map<String, Object> getConstants() {
protected Map<String, Object> getTypedExportedConstants() {
// When the app is killed, it doesn't start the activity so no need to wait for it
if (!isAppKilled()) {
// This is work-around for the RN problem described here:
Expand All @@ -52,13 +40,6 @@ public Map<String, Object> getConstants() {
}};
}

/**
* Looks like a bug in RN, without it this module is invisible
* in NativeModules.
*/
@ReactMethod
public void foo() {}

private void waitForActivity() {
for (int tries = 0; tries < ACTIVITY_WAIT_TRIES && !isActivityReady(); tries++) {
sleep(ACTIVITY_WAIT_INTERVAL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
package com.reactnativelauncharguments;

import com.facebook.react.ReactPackage;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.TurboReactPackage;
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 java.util.HashMap;
import java.util.Map;

import java.util.Collections;
import java.util.List;
public class LaunchArgumentsPackage extends TurboReactPackage {

public class LaunchArgumentsPackage implements ReactPackage {

@Nullable
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
public NativeModule getModule(@NonNull 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<>();
moduleInfos.put(
LaunchArgumentsModule.NAME,
new ReactModuleInfo(
LaunchArgumentsModule.NAME,
LaunchArgumentsModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
true // isTurboModule
));
return moduleInfos;
};
}
}
47 changes: 31 additions & 16 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions ios/LaunchArguments.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#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
10 changes: 0 additions & 10 deletions ios/LaunchArguments.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ @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
{
Expand Down Expand Up @@ -115,12 +113,4 @@ - (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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"react-native": ">=0.60.0-rc.0 <1.0.x"
},
"devDependencies": {
"react-native": "0.79.6",
"react": "19.0.0",
"react-native": "0.79.6",
"typescript": "5.8.2"
},
"codegenConfig": {
Expand Down
16 changes: 7 additions & 9 deletions react-native-launch-arguments.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ 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,mm}"
s.source_files = "ios/**/*.{h,m,swift}"
s.requires_arc = true

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.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
s.compiler_flags = '-DRCT_NEW_ARCH_ENABLED'
end
Loading
Loading