Skip to content

Commit

Permalink
fix old arch build
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed Nov 3, 2024
1 parent 52d9aa9 commit 681dce0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DerivedData
*.xcuserstate
project.xcworkspace
Pods
vendor


# Android/IntelliJ
Expand Down
16 changes: 8 additions & 8 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1761,16 +1761,16 @@ SPEC CHECKSUMS:
React-CoreModules: b4437acf2ef25ce3689c84df661dc5d806559b35
React-cxxreact: 6125cd820da7e18f9ca8343b3c42ee61634a4e0d
React-debug: f474f5c202a277f76c81bf7cf26284f2c09880d7
React-defaultsnativemodule: 7141fa704531cbf7a7e7af3bc02adfa367e831a7
React-domnativemodule: c1806b8584a53ed912012a4d8b2c6f96a84c77a3
React-defaultsnativemodule: 05f1a83669c4f01b5761b58ca0968306c99f3d50
React-domnativemodule: 64f3f5089cf214c31aa1821dd8fd4abc481baa91
React-Fabric: ba9636cfc7f9b77df6cb7edb2c70d0237026404b
React-FabricComponents: c408da05a4ea5ba071732245b4a7f48f904e610a
React-FabricImage: c409858f319f11709b49ffa6c5bca4faf794cb44
React-featureflags: 929732439d139ac0662e08f009f1a51ed2b91ed3
React-featureflagsnativemodule: 02dd903d4cbe4fae0e6cd02bc32a09d30543282f
React-featureflagsnativemodule: 2f899ad011b6b1a8aa8babe4fafa0a68725faeb6
React-graphics: a5cad35307286e9f83e212834e95fef4010d03d0
React-hermes: 14aafa9630579b84c2167b563bdb8c811970a03e
React-idlecallbacksnativemodule: 69581ac44bd355acce3739c3fe380c0f6d7a6d09
React-idlecallbacksnativemodule: ba1475765a2900e1adc76ce45a625ef5f79fdc19
React-ImageManager: 41945afb3ace0c52255057ec4ae6af6f5a23539f
React-jserrorhandler: ecbc4622df7ab3d0066a4313cde4172d45745508
React-jsi: ff383df87c7047e976a66be45df59e4e0db5346e
Expand All @@ -1779,17 +1779,17 @@ SPEC CHECKSUMS:
React-jsitracing: 654f4d9cb9fd99b3d96f239ceb215ae49ce28ac0
React-logger: 97c9dafae1f1a638001a9d1d0e93d431f2f9cb7b
React-Mapbuffer: 3146a13424f9fec2ea1f1462d49d566e4d69b732
React-microtasksnativemodule: 02d218c79c72d373a92a8552183f4ead0d1c6e05
react-native-mmkv-storage: 3b20fe33c3b4609d7c2796fad97a32a738004602
React-microtasksnativemodule: 8fa0a3d8542f6ae7712deebe0802ee17a623718b
react-native-mmkv-storage: d4893c2916c9cffd481d0fce91c311981b6323e6
React-nativeconfig: 93fe8c85a8c40820c57814e30f3e44b94c995a7b
React-NativeModulesApple: b3e076fd0d7b73417fe1e8c8b26e3c57ae9b74aa
React-perflogger: 1c55bcd3c392137cbaf0d21d8bb87ce9a0cebb15
React-performancetimeline: e89249db10b8f7bf8f72c2e9bd471ac37d48b753
React-RCTActionSheet: 9407c795fbeee35da2dae3cd6b5c4e5da6ff8bd3
React-RCTAnimation: 7ee1c2a77aab7e5c568611d8092a994cfcbe8410
React-RCTAppDelegate: 10c2b0c434baf5a71b53d5c86c4d8d0dbd6bb380
React-RCTAppDelegate: e7b835203804bfd12a8baad30ab4c67f7da7bf24
React-RCTBlob: 761072706300d22624ec2d6bf860b77d95ebd3da
React-RCTFabric: 871d38933a94554d9e27963aa4bb67184dc7529e
React-RCTFabric: a6c44c606009f889ef7431e71f03c5339fb72e6e
React-RCTImage: b6614fde902ec9647f15236da94df2d24c40523f
React-RCTLinking: 25950eda5d5f786bfb3daf513ea7d848555a2a93
React-RCTNetwork: b69407c4119fd7a1cc07db4a94563f2546f8770d
Expand Down
30 changes: 28 additions & 2 deletions ios/MMKVStorage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ void setServiceName(NSString *alias, NSString *serviceName) {
// Installing JSI Bindings as done by
// https://github.com/mrousavy/react-native-mmkv

#ifdef RCT_NEW_ARCH_ENABLED

- (NSNumber *)install {
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)_bridge;
if (cxxBridge == nil) {
return @YES;
return @NO;
}

auto jsiRuntime = (jsi::Runtime*) cxxBridge.runtime;
if (jsiRuntime == nil) {
return @YES;
return @NO;
}

mmkvInstances = [NSMutableDictionary dictionary];
Expand All @@ -132,6 +134,30 @@ - (NSNumber *)install {
return @YES;
}

#else
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
RCTCxxBridge* cxxBridge = (RCTCxxBridge*)_bridge;
if (cxxBridge == nil) {
return @false;
}

auto jsiRuntime = (jsi::Runtime*) cxxBridge.runtime;
if (jsiRuntime == nil) {
return @false;
}

mmkvInstances = [NSMutableDictionary dictionary];
serviceNames = [NSMutableDictionary dictionary];

[self migrate];

RCTBridge *bridge = [RCTBridge currentBridge];

install(*(jsi::Runtime *)jsiRuntime);
return @true;
}
#endif

MMKV *createInstance(NSString *ID, MMKVMode mode, NSString *key,
NSString *path) {

Expand Down
6 changes: 3 additions & 3 deletions src/mmkv/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export function init() {
try {
if (!isLoaded()) {
const installed = mmkvBridgeModule.install();
if (!installed) throw new Error('JSI bindings were not installed for: MMKVNative');
if (!installed) throw new Error('JSI bindings were not installed for: MMKVStorage');

if (!isLoaded()) {
throw new Error('JSI bindings installation failed for: MMKVNative');
throw new Error('JSI bindings installation failed for: MMKVStorage');
}
return installed;
}
return true;
} catch (e) {
console.log('JSI bindings were not installed for: MMKVNative');
console.error('JSI bindings were not installed for: MMKVStorage', e);
return false;
}
}
2 changes: 1 addition & 1 deletion src/mmkvloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class MMKVLoader {
* Create the instance with the given options.
*/
initialize() {
if (!init()) throw new Error('MMKVNative bindings not installed');
if (!init()) throw new Error('MMKVStorage bindings not installed');
currentInstancesStatus[this.options.instanceID] = false;
options[this.options.instanceID] = this.options;
let instance = new MMKVInstance(this.options.instanceID);
Expand Down
4 changes: 2 additions & 2 deletions src/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const isDebugMode =
const isTurboModuleEnabled = global.__turboModuleProxy != null;

export const mmkvBridgeModule: {
/**
/*
* Install JSI bindings
*/
install: () => boolean;
} = !isDebugMode
? isTurboModuleEnabled
? require('./NativeMMKVStorage').default
: require('react-native').NativeModules.MMKVNative
: require('react-native').NativeModules.MMKVStorage
: {
install: () => {
console.warn(
Expand Down

0 comments on commit 681dce0

Please sign in to comment.