Skip to content

Commit

Permalink
feat(plugin): fsapp assets
Browse files Browse the repository at this point in the history
  • Loading branch information
crherman7 committed Dec 30, 2024
1 parent 39f220e commit 5cb8fba
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/app-env/android/.project
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>
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
47 changes: 47 additions & 0 deletions packages/plugin-fsapp/assets/EnvSwitcher.java
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);
}
}
33 changes: 33 additions & 0 deletions packages/plugin-fsapp/assets/EnvSwitcher.m
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
24 changes: 24 additions & 0 deletions packages/plugin-fsapp/assets/EnvSwitcherPackage.java
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));
}};
}
}
26 changes: 26 additions & 0 deletions packages/plugin-fsapp/assets/NativeConstants.java
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;
}
}
22 changes: 22 additions & 0 deletions packages/plugin-fsapp/assets/NativeConstants.m
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
24 changes: 24 additions & 0 deletions packages/plugin-fsapp/assets/NativeConstantsPackage.java
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));
}};
}
}

0 comments on commit 5cb8fba

Please sign in to comment.