-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>android</name> | ||
<comment>Project android created by Buildship.</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
</projectDescription> |
13 changes: 13 additions & 0 deletions
13
packages/app-env/android/.settings/org.eclipse.buildship.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
arguments=--init-script /var/folders/9d/262q7prd0bs8bdhjpmhl2nvm0000gn/T/db3b08fc4a9ef609cb16b96b200fa13e563f396e9bb1ed0905fdab7bc3bc513b.gradle | ||
auto.sync=false | ||
build.scans.enabled=false | ||
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(8.9)) | ||
connection.project.dir= | ||
eclipse.preferences.version=1 | ||
gradle.user.home= | ||
java.home=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home | ||
jvm.arguments= | ||
offline.mode=false | ||
override.workspace.settings=true | ||
show.console.view=true | ||
show.executions.view=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.app; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
|
||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class EnvSwitcher extends ReactContextBaseJavaModule { | ||
private SharedPreferences sharedPref; | ||
|
||
public EnvSwitcher(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
|
||
sharedPref = reactContext.getSharedPreferences("__ENV_NAME_STORE", Context.MODE_PRIVATE); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "EnvSwitcher"; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getConstants() { | ||
final String initialEnvName = "prod"; | ||
|
||
return new HashMap<String, Object>() {{ | ||
put("envName", sharedPref.getString("envName", initialEnvName)); | ||
}}; | ||
} | ||
|
||
@SuppressLint("ApplySharedPref") | ||
@ReactMethod | ||
public void setEnv(String name, Promise promise) { | ||
final SharedPreferences.Editor editor = sharedPref.edit(); | ||
editor.putString("envName", name); | ||
editor.commit(); | ||
|
||
promise.resolve(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface EnvSwitcher : NSObject <RCTBridgeModule> | ||
@end | ||
|
||
|
||
@implementation EnvSwitcher | ||
RCT_EXPORT_MODULE(); | ||
|
||
+ (BOOL)requiresMainQueueSetup | ||
{ | ||
return NO; | ||
} | ||
|
||
- (NSDictionary *)constantsToExport { | ||
NSString *initialEnvName = @"prod"; | ||
NSString *envName = [[NSUserDefaults standardUserDefaults] | ||
objectForKey:@"envName"]; | ||
return @{ | ||
@"envName": envName ?: initialEnvName | ||
}; | ||
} | ||
|
||
RCT_EXPORT_METHOD(setEnv:(nonnull NSString *)name | ||
resolver:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)reject) { | ||
[[NSUserDefaults standardUserDefaults] setObject:(name ?: @"") forKey:@"envName"]; | ||
[[NSUserDefaults standardUserDefaults] synchronize]; | ||
resolve(nil); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.app; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class EnvSwitcherPackage implements ReactPackage { | ||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules(final ReactApplicationContext reactContext) { | ||
return new ArrayList<NativeModule>() {{ | ||
add(new EnvSwitcher(reactContext)); | ||
}}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.app; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class NativeConstants extends ReactContextBaseJavaModule { | ||
public NativeConstants(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "NativeConstants"; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getConstants() { | ||
final Map<String, Object> constants = new HashMap<>(); | ||
constants.put("ShowDevMenu", "true"); | ||
|
||
return constants; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface NativeConstants : NSObject <RCTBridgeModule> | ||
@end | ||
|
||
|
||
@implementation NativeConstants | ||
RCT_EXPORT_MODULE(); | ||
|
||
+ (BOOL)requiresMainQueueSetup | ||
{ | ||
return NO; | ||
} | ||
|
||
- (NSDictionary *)constantsToExport { | ||
return @{ | ||
@"ShowDevMenu": @"true" | ||
}; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.app; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class NativeConstantsPackage implements ReactPackage { | ||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules(final ReactApplicationContext reactContext) { | ||
return new ArrayList<NativeModule>() {{ | ||
add(new NativeConstants(reactContext)); | ||
}}; | ||
} | ||
} |