From e80431faa41977a528a92a02c795e918807a7fa1 Mon Sep 17 00:00:00 2001 From: Protik Biswas Date: Tue, 2 Sep 2025 15:22:20 +0530 Subject: [PATCH 1/7] fixing android build --- .../source/codegen/jni/CMakeLists.txt | 13 -------- .../generated/source/codegen/jni/empty.cpp | 2 -- index.js | 30 ++----------------- 3 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 android/build/generated/source/codegen/jni/CMakeLists.txt delete mode 100644 android/build/generated/source/codegen/jni/empty.cpp diff --git a/android/build/generated/source/codegen/jni/CMakeLists.txt b/android/build/generated/source/codegen/jni/CMakeLists.txt deleted file mode 100644 index b8ca81aa..00000000 --- a/android/build/generated/source/codegen/jni/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Minimal stub CMakeLists for missing codegen outputs. -# This defines the react_codegen_RNCConfigModule target so native builds -# that expect generated code can link against a placeholder library. -cmake_minimum_required(VERSION 3.4.1) - -# Create a small static library with a trivial source file so CMake has a target to link. -add_library(react_codegen_RNCConfigModule STATIC "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp") - -# Expose the current source dir (if other CMake code expects include dirs) -target_include_directories(react_codegen_RNCConfigModule PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -# Prevent warnings when linked against: set an empty interface -target_compile_definitions(react_codegen_RNCConfigModule INTERFACE "REACT_NATIVE_CONFIG_STUB") diff --git a/android/build/generated/source/codegen/jni/empty.cpp b/android/build/generated/source/codegen/jni/empty.cpp deleted file mode 100644 index 772f76b7..00000000 --- a/android/build/generated/source/codegen/jni/empty.cpp +++ /dev/null @@ -1,2 +0,0 @@ -// Auto-generated stub file to satisfy CMake when real codegen output is not present. -extern "C" void __react_native_config_codegen_stub() {} diff --git a/index.js b/index.js index 6a3e7061..b2aac56e 100644 --- a/index.js +++ b/index.js @@ -3,34 +3,8 @@ // 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, TurboModuleRegistry, Platform } from 'react-native'; +import { NativeModules } from 'react-native'; -// New-arch TurboModule name should match native module name -const TM_NAME = 'RNCConfigModule'; +export const Config = NativeModules.RNCConfigModule || {} -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; \ No newline at end of file From dd2316ecde3c745d023a6db204b7fb569fb2ab06 Mon Sep 17 00:00:00 2001 From: Protik Biswas Date: Wed, 3 Sep 2025 19:18:54 +0530 Subject: [PATCH 2/7] reverting chnages --- package.json | 27 ++-------------------- src/NativeRNCConfig.ts | 12 ---------- windows/code/RNCConfig.cpp | 41 +-------------------------------- windows/code/RNCConfig.h | 21 +---------------- windows/code/generate-header.js | 9 -------- 5 files changed, 4 insertions(+), 106 deletions(-) delete mode 100644 src/NativeRNCConfig.ts diff --git a/package.json b/package.json index 686b9825..4daadfbf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-config", - "version": "1.5.6", + "version": "1.5.7", "description": "Expose config variables to React Native apps", "keywords": [ "env", @@ -27,7 +27,6 @@ "android/", "ios/", "windows/", - "src/", "index.js", "index.d.ts", "react-native-config.podspec", @@ -37,15 +36,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" @@ -54,19 +45,5 @@ "react-native-windows": { "optional": true } - }, - "codegenConfig": { - "name": "RNCConfigModule", - "type": "modules", - "jsSrcsDir": "./src", - "android": { - "javaPackageName": "com.luggit.reactnativeconfig" - }, - "ios": { - "prefix": "RNC" - }, - "windows": { - "cppNamespace": "RNCConfig" - } } } diff --git a/src/NativeRNCConfig.ts b/src/NativeRNCConfig.ts deleted file mode 100644 index 09baa717..00000000 --- a/src/NativeRNCConfig.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { TurboModule } from 'react-native'; -import { TurboModuleRegistry } from 'react-native'; - -export interface Spec extends TurboModule { - // Synchronous getters (supported on Windows TurboModules) - getAll(): { [key: string]: string }; - get(key: string): string; - // Optional Composition info hook - compositionInfo?(): string; -} - -export default TurboModuleRegistry.getEnforcing('RNCConfigModule'); diff --git a/windows/code/RNCConfig.cpp b/windows/code/RNCConfig.cpp index b404bae4..7c95b4ef 100644 --- a/windows/code/RNCConfig.cpp +++ b/windows/code/RNCConfig.cpp @@ -1,41 +1,2 @@ - #include "pch.h" +#include "pch.h" #include "RNCConfig.h" -#if __has_include("RNCConfigValues.h") -#include "RNCConfigValues.h" -#endif -#include -using namespace Microsoft::ReactNative; - -namespace RNCConfig -{ - JSValueObject RNCConfigModule::getAll() noexcept - { - JSValueObject obj{}; - #if __has_include("RNCConfigValuesObject.inc.g.h") - #include "RNCConfigValuesObject.inc.g.h" - #endif - return obj; - } - - std::string RNCConfigModule::get(std::string const& key) noexcept - { - #if __has_include("RNCConfigValuesGet.inc.g.h") - #include "RNCConfigValuesGet.inc.g.h" - #endif - return std::string{}; - } - - void RNCConfigModule::ProvideConstants(ReactConstantProvider& provider) noexcept - { - #if __has_include("RNCConfigValuesConstants.inc.g.h") - #include "RNCConfigValuesConstants.inc.g.h" - #endif - } - - std::string RNCConfigModule::compositionInfo() noexcept - { - // No-op informational string; placeholder to indicate Composition can be used in this module - // In a real implementation, you'd create a Compositor and maybe return feature info. - return std::string{"CompositionReady"}; - } -} diff --git a/windows/code/RNCConfig.h b/windows/code/RNCConfig.h index 2b6c176f..2fe51131 100644 --- a/windows/code/RNCConfig.h +++ b/windows/code/RNCConfig.h @@ -11,26 +11,7 @@ namespace RNCConfig REACT_MODULE(RNCConfigModule); struct RNCConfigModule { -#if __has_include("RNCConfigValuesModule.inc.g.h") -#include "RNCConfigValuesModule.inc.g.h" -#else -// Generated constants will be included at build-time -#endif - - // TurboModule-friendly sync APIs - REACT_SYNC_METHOD(getAll); - Microsoft::ReactNative::JSValueObject getAll() noexcept; - - REACT_SYNC_METHOD(get); - std::string get(std::string const& key) noexcept; - - // Keep constants available via the classic constants provider too - REACT_CONSTANT_PROVIDER(ProvideConstants); - void ProvideConstants(Microsoft::ReactNative::ReactConstantProvider& provider) noexcept; - - // Example Windows.UI.Composition usage exposed via a sync method - REACT_SYNC_METHOD(compositionInfo); - std::string compositionInfo() noexcept; + #include "RNCConfigValuesModule.inc.g.h" }; } diff --git a/windows/code/generate-header.js b/windows/code/generate-header.js index 256dd917..4a4ff03e 100644 --- a/windows/code/generate-header.js +++ b/windows/code/generate-header.js @@ -34,12 +34,6 @@ function generateFiles(vars) { let nativeCode = ''; // 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 - let keyGetter = ''; - // Snippet for ReactConstantProvider - let constantsProvider = ''; nativeCode += '#include\n' nativeCode += 'namespace ReactNativeConfig {\n' for (let {key, value} of vars) { @@ -54,9 +48,6 @@ function generateFiles(vars) { nativeCode +='}\n' updateFile(nativeCode, path.join(outDir, 'RNCConfigValues.h')) updateFile(rnCode, path.join(outDir, 'RNCConfigValuesModule.inc.g.h')) - updateFile(objectBuilder, path.join(outDir, 'RNCConfigValuesObject.inc.g.h')) - updateFile(keyGetter, path.join(outDir, 'RNCConfigValuesGet.inc.g.h')) - updateFile(constantsProvider, path.join(outDir, 'RNCConfigValuesConstants.inc.g.h')) } // Escape the string so it will work with C++ From 68500ad5c4f2a07dcfee5f2aaf1266daa863ba29 Mon Sep 17 00:00:00 2001 From: Protik Biswas Date: Thu, 4 Sep 2025 21:16:41 +0530 Subject: [PATCH 3/7] adding back changes --- index.js | 32 ++++++++++++++++++++++++--- windows/code/RNCConfig.cpp | 39 +++++++++++++++++++++++++++++++++ windows/code/RNCConfig.h | 22 +++++++++++++++++-- windows/code/generate-header.js | 11 ++++++++++ 4 files changed, 99 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index e398c70a..6a3e7061 100644 --- a/index.js +++ b/index.js @@ -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; \ No newline at end of file diff --git a/windows/code/RNCConfig.cpp b/windows/code/RNCConfig.cpp index 7c95b4ef..bab11f00 100644 --- a/windows/code/RNCConfig.cpp +++ b/windows/code/RNCConfig.cpp @@ -1,2 +1,41 @@ #include "pch.h" #include "RNCConfig.h" +#if __has_include("RNCConfigValues.h") +#include "RNCConfigValues.h" +#endif +#include +using namespace Microsoft::ReactNative; + +namespace RNCConfig +{ + JSValueObject RNCConfigModule::getAll() noexcept + { + JSValueObject obj{}; + #if __has_include("RNCConfigValuesObject.inc.g.h") + #include "RNCConfigValuesObject.inc.g.h" + #endif + return obj; + } + + std::string RNCConfigModule::get(std::string const& key) noexcept + { + #if __has_include("RNCConfigValuesGet.inc.g.h") + #include "RNCConfigValuesGet.inc.g.h" + #endif + return std::string{}; + } + + void RNCConfigModule::ProvideConstants(ReactConstantProvider& provider) noexcept + { + #if __has_include("RNCConfigValuesConstants.inc.g.h") + #include "RNCConfigValuesConstants.inc.g.h" + #endif + } + + std::string RNCConfigModule::compositionInfo() noexcept + { + // No-op informational string; placeholder to indicate Composition can be used in this module + // In a real implementation, you'd create a Compositor and maybe return feature info. + return std::string{"CompositionReady"}; + } +} diff --git a/windows/code/RNCConfig.h b/windows/code/RNCConfig.h index 2fe51131..4a2f967a 100644 --- a/windows/code/RNCConfig.h +++ b/windows/code/RNCConfig.h @@ -11,7 +11,25 @@ namespace RNCConfig REACT_MODULE(RNCConfigModule); struct RNCConfigModule { - #include "RNCConfigValuesModule.inc.g.h" +#if __has_include("RNCConfigValuesModule.inc.g.h") +#include "RNCConfigValuesModule.inc.g.h" +#else +// Generated constants will be included at build-time +#endif + + // TurboModule-friendly sync APIs + REACT_SYNC_METHOD(getAll); + Microsoft::ReactNative::JSValueObject getAll() noexcept; + + REACT_SYNC_METHOD(get); + std::string get(std::string const& key) noexcept; + + // Keep constants available via the classic constants provider too + REACT_CONSTANT_PROVIDER(ProvideConstants); + void ProvideConstants(Microsoft::ReactNative::ReactConstantProvider& provider) noexcept; + + // Example Windows.UI.Composition usage exposed via a sync method + REACT_SYNC_METHOD(compositionInfo); + std::string compositionInfo() noexcept; }; } - diff --git a/windows/code/generate-header.js b/windows/code/generate-header.js index 4a4ff03e..418d91f8 100644 --- a/windows/code/generate-header.js +++ b/windows/code/generate-header.js @@ -34,6 +34,14 @@ 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 + let keyGetter = ''; + // Snippet for ReactConstantProvider + let constantsProvider = ''; nativeCode += '#include\n' nativeCode += 'namespace ReactNativeConfig {\n' for (let {key, value} of vars) { @@ -48,6 +56,9 @@ function generateFiles(vars) { nativeCode +='}\n' updateFile(nativeCode, path.join(outDir, 'RNCConfigValues.h')) updateFile(rnCode, path.join(outDir, 'RNCConfigValuesModule.inc.g.h')) + updateFile(objectBuilder, path.join(outDir, 'RNCConfigValuesObject.inc.g.h')) + updateFile(keyGetter, path.join(outDir, 'RNCConfigValuesGet.inc.g.h')) + updateFile(constantsProvider, path.join(outDir, 'RNCConfigValuesConstants.inc.g.h')) } // Escape the string so it will work with C++ From 6d397d63a823fb13da3a9fcb4b3dd0963751f3af Mon Sep 17 00:00:00 2001 From: Protik Biswas Date: Fri, 5 Sep 2025 10:56:17 +0530 Subject: [PATCH 4/7] adding gradle changes --- Example/android/app/build.gradle | 23 +++--- .../java/com/example/ReactNativeFlipper.java | 72 ------------------- 2 files changed, 12 insertions(+), 83 deletions(-) diff --git a/Example/android/app/build.gradle b/Example/android/app/build.gradle index 3041083c..3086e9f8 100644 --- a/Example/android/app/build.gradle +++ b/Example/android/app/build.gradle @@ -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/"; diff --git a/Example/android/app/src/debug/java/com/example/ReactNativeFlipper.java b/Example/android/app/src/debug/java/com/example/ReactNativeFlipper.java index a1b70b8a..e69de29b 100644 --- a/Example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +++ b/Example/android/app/src/debug/java/com/example/ReactNativeFlipper.java @@ -1,72 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - *

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()); - } - } - } -} From d7e44314dbe0d805ee82f5ea13bbddde517f9c2b Mon Sep 17 00:00:00 2001 From: Protik Biswas Date: Fri, 5 Sep 2025 11:00:41 +0530 Subject: [PATCH 5/7] adding spec file --- src/NativeRNCConfig.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/NativeRNCConfig.ts diff --git a/src/NativeRNCConfig.ts b/src/NativeRNCConfig.ts new file mode 100644 index 00000000..af673c60 --- /dev/null +++ b/src/NativeRNCConfig.ts @@ -0,0 +1,12 @@ +import type { TurboModule } from 'react-native'; +import { TurboModuleRegistry } from 'react-native'; + +export interface Spec extends TurboModule { + // Synchronous getters (supported on Windows TurboModules) + getAll(): { [key: string]: string }; + get(key: string): string; + // Optional Composition info hook + compositionInfo?(): string; +} + +export default TurboModuleRegistry.getEnforcing('RNCConfigModule'); \ No newline at end of file From fd56a5cd70d8b9a69e536d24b9e181fef402829c Mon Sep 17 00:00:00 2001 From: Protik Biswas Date: Fri, 5 Sep 2025 11:07:10 +0530 Subject: [PATCH 6/7] adding package.json changes --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 4daadfbf..38d9b572 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "android/", "ios/", "windows/", + "src", "index.js", "index.d.ts", "react-native-config.podspec", From 98077afdf3eb9501e1f81d163c644134472b1afd Mon Sep 17 00:00:00 2001 From: Protik Biswas Date: Fri, 5 Sep 2025 11:07:44 +0530 Subject: [PATCH 7/7] adding package.json change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38d9b572..3a8e6332 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "android/", "ios/", "windows/", - "src", + "src/", "index.js", "index.d.ts", "react-native-config.podspec",