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
23 changes: 12 additions & 11 deletions Example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,18 @@ dependencies {

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}

debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
// Flipper dependencies disabled for build compatibility
// debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
// exclude group:'com.facebook.fbjni'
// }

// debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
// exclude group:'com.facebook.flipper'
// }

// debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
// exclude group:'com.facebook.flipper'
// }

if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.example;

import android.content.Context;
import com.facebook.flipper.android.AndroidFlipperClient;
import com.facebook.flipper.android.utils.FlipperUtils;
import com.facebook.flipper.core.FlipperClient;
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.modules.network.NetworkingModule;
import okhttp3.OkHttpClient;

public class ReactNativeFlipper {
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
if (FlipperUtils.shouldEnableFlipper(context)) {
final FlipperClient client = AndroidFlipperClient.getInstance(context);

client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
client.addPlugin(new ReactFlipperPlugin());
client.addPlugin(new DatabasesFlipperPlugin(context));
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
client.addPlugin(CrashReporterPlugin.getInstance());

NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
NetworkingModule.setCustomClientBuilder(
new NetworkingModule.CustomClientBuilder() {
@Override
public void apply(OkHttpClient.Builder builder) {
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
}
});
client.addPlugin(networkFlipperPlugin);
client.start();

// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
// Hence we run if after all native modules have been initialized
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
if (reactContext == null) {
reactInstanceManager.addReactInstanceEventListener(
new ReactInstanceManager.ReactInstanceEventListener() {
@Override
public void onReactContextInitialized(ReactContext reactContext) {
reactInstanceManager.removeReactInstanceEventListener(this);
reactContext.runOnNativeModulesQueueThread(
new Runnable() {
@Override
public void run() {
client.addPlugin(new FrescoFlipperPlugin());
}
});
}
});
} else {
client.addPlugin(new FrescoFlipperPlugin());
}
}
}
}
32 changes: 29 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,34 @@
// Bridge to:
// Android: buildConfigField vars set in build.gradle, and exported via ReactConfig
// iOS: config vars set in xcconfig and exposed via RNCConfig.m
import { NativeModules } from 'react-native';
import { NativeModules, TurboModuleRegistry, Platform } from 'react-native';

export const Config = NativeModules.RNCConfigModule || {}
// New-arch TurboModule name should match native module name
const TM_NAME = 'RNCConfigModule';

export default Config;
function getTurboModule() {
try {
if (TurboModuleRegistry?.get) {
return TurboModuleRegistry.get(TM_NAME);
}
} catch (_) {}
return null;
}

const Turbo = getTurboModule();
const Paper = NativeModules?.RNCConfigModule;

let config = {};
if (Turbo) {
// Prefer TM sync getAll when available to return a plain object
if (typeof Turbo.getAll === 'function') {
try { config = Turbo.getAll() || {}; } catch (_) { config = {}; }
} else {
config = Turbo;
}
} else if (Paper) {
config = Paper;
}

export const Config = config;
export default Config;
26 changes: 2 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-config",
"version": "1.5.9",
"version": "1.5.7",
"description": "Expose config variables to React Native apps",
"keywords": [
"env",
Expand Down Expand Up @@ -37,15 +37,7 @@
"license": "MIT",
"devDependencies": {
"@semantic-release/git": "^10.0.1",
"semantic-release": "^19.0.5",
"jest": "^29.7.0",
"@types/jest": "^29.5.12"
},
"dependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.0",
"@babel/preset-react": "^7.24.7",
"babel-jest": "^29.7.0"
"semantic-release": "^19.0.5"
},
"peerDependencies": {
"react-native-windows": ">=0.61"
Expand All @@ -54,19 +46,5 @@
"react-native-windows": {
"optional": true
}
},
"codegenConfig": {
"name": "RNCConfigModule",
"type": "modules",
"jsSrcsDir": "./src",
"android": {
"javaPackageName": "com.luggit.reactnativeconfig"
},
"ios": {
"prefix": "RNC"
},
"windows": {
"cppNamespace": "RNCConfig"
}
}
}
2 changes: 1 addition & 1 deletion src/NativeRNCConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export interface Spec extends TurboModule {
compositionInfo?(): string;
}

export default TurboModuleRegistry.getEnforcing<Spec>('RNCConfigModule');
export default TurboModuleRegistry.getEnforcing<Spec>('RNCConfigModule');
2 changes: 1 addition & 1 deletion windows/code/RNCConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "pch.h"
#include "pch.h"
#include "RNCConfig.h"
#if __has_include("RNCConfigValues.h")
#include "RNCConfigValues.h"
Expand Down
1 change: 0 additions & 1 deletion windows/code/RNCConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ namespace RNCConfig
std::string compositionInfo() noexcept;
};
}

2 changes: 2 additions & 0 deletions windows/code/generate-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function generateFiles(vars) {
let nativeCode = '';
// React Native Module code: attribute-based constants block
let rnCode = '';
// React Native Module code: attribute-based constants block
let rnCode = '';
// Snippets for building a JS object with all constants
let objectBuilder = '';
// Snippet for a key-based getter switch/if chain
Expand Down