From 5cb8fba98b40819f08c19636e35bbff06632a686 Mon Sep 17 00:00:00 2001 From: Chris Herman Date: Mon, 30 Dec 2024 08:00:44 -0500 Subject: [PATCH] feat(plugin): fsapp assets --- packages/app-env/android/.project | 17 +++++++ .../org.eclipse.buildship.core.prefs | 13 +++++ packages/plugin-fsapp/assets/EnvSwitcher.java | 47 +++++++++++++++++++ packages/plugin-fsapp/assets/EnvSwitcher.m | 33 +++++++++++++ .../assets/EnvSwitcherPackage.java | 24 ++++++++++ .../plugin-fsapp/assets/NativeConstants.java | 26 ++++++++++ .../plugin-fsapp/assets/NativeConstants.m | 22 +++++++++ .../assets/NativeConstantsPackage.java | 24 ++++++++++ 8 files changed, 206 insertions(+) create mode 100644 packages/app-env/android/.project create mode 100644 packages/app-env/android/.settings/org.eclipse.buildship.core.prefs create mode 100644 packages/plugin-fsapp/assets/EnvSwitcher.java create mode 100644 packages/plugin-fsapp/assets/EnvSwitcher.m create mode 100644 packages/plugin-fsapp/assets/EnvSwitcherPackage.java create mode 100644 packages/plugin-fsapp/assets/NativeConstants.java create mode 100644 packages/plugin-fsapp/assets/NativeConstants.m create mode 100644 packages/plugin-fsapp/assets/NativeConstantsPackage.java diff --git a/packages/app-env/android/.project b/packages/app-env/android/.project new file mode 100644 index 0000000000..3964dd3f5b --- /dev/null +++ b/packages/app-env/android/.project @@ -0,0 +1,17 @@ + + + android + Project android created by Buildship. + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/packages/app-env/android/.settings/org.eclipse.buildship.core.prefs b/packages/app-env/android/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000000..d773116fdc --- /dev/null +++ b/packages/app-env/android/.settings/org.eclipse.buildship.core.prefs @@ -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 diff --git a/packages/plugin-fsapp/assets/EnvSwitcher.java b/packages/plugin-fsapp/assets/EnvSwitcher.java new file mode 100644 index 0000000000..4f4d290492 --- /dev/null +++ b/packages/plugin-fsapp/assets/EnvSwitcher.java @@ -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 getConstants() { + final String initialEnvName = "prod"; + + return new HashMap() {{ + 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); + } +} diff --git a/packages/plugin-fsapp/assets/EnvSwitcher.m b/packages/plugin-fsapp/assets/EnvSwitcher.m new file mode 100644 index 0000000000..8d7d1d7e28 --- /dev/null +++ b/packages/plugin-fsapp/assets/EnvSwitcher.m @@ -0,0 +1,33 @@ +#import +#import + +@interface EnvSwitcher : NSObject +@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 diff --git a/packages/plugin-fsapp/assets/EnvSwitcherPackage.java b/packages/plugin-fsapp/assets/EnvSwitcherPackage.java new file mode 100644 index 0000000000..2148469428 --- /dev/null +++ b/packages/plugin-fsapp/assets/EnvSwitcherPackage.java @@ -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 createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules(final ReactApplicationContext reactContext) { + return new ArrayList() {{ + add(new EnvSwitcher(reactContext)); + }}; + } +} diff --git a/packages/plugin-fsapp/assets/NativeConstants.java b/packages/plugin-fsapp/assets/NativeConstants.java new file mode 100644 index 0000000000..2b656acb46 --- /dev/null +++ b/packages/plugin-fsapp/assets/NativeConstants.java @@ -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 getConstants() { + final Map constants = new HashMap<>(); + constants.put("ShowDevMenu", "true"); + + return constants; + } +} diff --git a/packages/plugin-fsapp/assets/NativeConstants.m b/packages/plugin-fsapp/assets/NativeConstants.m new file mode 100644 index 0000000000..ab9e3a8a64 --- /dev/null +++ b/packages/plugin-fsapp/assets/NativeConstants.m @@ -0,0 +1,22 @@ +#import +#import + +@interface NativeConstants : NSObject +@end + + +@implementation NativeConstants +RCT_EXPORT_MODULE(); + ++ (BOOL)requiresMainQueueSetup +{ + return NO; +} + +- (NSDictionary *)constantsToExport { + return @{ + @"ShowDevMenu": @"true" + }; +} + +@end diff --git a/packages/plugin-fsapp/assets/NativeConstantsPackage.java b/packages/plugin-fsapp/assets/NativeConstantsPackage.java new file mode 100644 index 0000000000..89c2f919ee --- /dev/null +++ b/packages/plugin-fsapp/assets/NativeConstantsPackage.java @@ -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 createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules(final ReactApplicationContext reactContext) { + return new ArrayList() {{ + add(new NativeConstants(reactContext)); + }}; + } +}