-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from zabojad/@thomasfetiveau/new-architecture
Add support for both old and new architecture
- Loading branch information
Showing
14 changed files
with
217 additions
and
89 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,8 @@ | ||
import type { TurboModule } from 'react-native'; | ||
import { TurboModuleRegistry } from 'react-native'; | ||
|
||
export interface Spec extends TurboModule { | ||
exitApp: () => void; | ||
} | ||
|
||
export default TurboModuleRegistry.getEnforcing<Spec>('RNExitApp'); |
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
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
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
18 changes: 18 additions & 0 deletions
18
android/src/main/java/com/github/wumke/RNExitApp/RNExitAppImpl.java
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,18 @@ | ||
package com.github.wumke.RNExitApp; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
|
||
class RNExitAppImpl { | ||
|
||
public static final String NAME = "RNExitApp"; | ||
|
||
ReactApplicationContext RCTContext; | ||
|
||
public RNExitAppImpl(ReactApplicationContext reactContext) { | ||
RCTContext = reactContext; | ||
} | ||
|
||
public void exitApp() { | ||
android.os.Process.killProcess(android.os.Process.myPid()); | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
android/src/main/java/com/github/wumke/RNExitApp/RNExitAppModule.java
This file was deleted.
Oops, something went wrong.
58 changes: 32 additions & 26 deletions
58
android/src/main/java/com/github/wumke/RNExitApp/RNExitAppPackage.java
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 |
---|---|---|
@@ -1,39 +1,45 @@ | ||
package com.github.wumke.RNExitApp; | ||
|
||
import java.util.Arrays; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.TurboReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
import com.facebook.react.module.model.ReactModuleInfo; | ||
import com.facebook.react.module.model.ReactModuleInfoProvider; | ||
|
||
public class RNExitAppPackage implements ReactPackage { | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Override | ||
public List<NativeModule> createNativeModules( | ||
ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
|
||
modules.add(new RNExitAppModule(reactContext)); | ||
|
||
return modules; | ||
} | ||
public class RNExitAppPackage extends TurboReactPackage { | ||
|
||
// override removed to be compatible with rn0.47+ | ||
//@Override | ||
public List<Class<? extends JavaScriptModule>> createJSModules() { | ||
|
||
return Collections.emptyList(); | ||
@Nullable | ||
@Override | ||
public NativeModule getModule(String name, ReactApplicationContext reactContext) { | ||
if (name.equals(RNExitAppImpl.NAME)) { | ||
return new RNExitApp(reactContext); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers( | ||
ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
public ReactModuleInfoProvider getReactModuleInfoProvider() { | ||
return () -> { | ||
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>(); | ||
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; | ||
moduleInfos.put( | ||
RNExitAppImpl.NAME, | ||
new ReactModuleInfo( | ||
RNExitAppImpl.NAME, | ||
RNExitAppImpl.NAME, | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
false, // hasConstants | ||
false, // isCxxModule | ||
isTurboModule // isTurboModule | ||
)); | ||
return moduleInfos; | ||
}; | ||
} | ||
|
||
} |
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,28 @@ | ||
package com.github.wumke.RNExitApp; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
|
||
import com.github.wumke.RNExitApp.NativeRNExitAppSpec; | ||
|
||
public class RNExitApp extends NativeRNExitAppSpec { | ||
|
||
private final RNExitAppImpl delegate; | ||
|
||
public RNExitApp(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
delegate = new RNExitAppImpl(reactContext); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getName() { | ||
return RNExitAppImpl.NAME; | ||
} | ||
|
||
@Override | ||
public void exitApp() { | ||
delegate.exitApp(); | ||
} | ||
} |
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,27 @@ | ||
package com.github.wumke.RNExitApp; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
|
||
import android.util.Log; | ||
|
||
public class RNExitApp extends ReactContextBaseJavaModule { | ||
|
||
private final RNExitAppImpl delegate; | ||
|
||
public RNExitApp(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
delegate = new RNExitAppImpl(reactContext); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return RNExitAppImpl.NAME; | ||
} | ||
|
||
@ReactMethod | ||
public void exitApp() { | ||
delegate.exitApp(); | ||
} | ||
} |
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
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,19 @@ | ||
#if __has_include(<React/RCTBridgeModule.h>) | ||
#import <React/RCTBridgeModule.h> | ||
#elif __has_include("RCTBridgeModule.h") | ||
#import "RCTBridgeModule.h" | ||
#else | ||
#import "React/RCTBridgeModule.h" | ||
#endif | ||
|
||
#if RCT_NEW_ARCH_ENABLED | ||
#import <React-Codegen/RNExitAppSpec/RNExitAppSpec.h> | ||
#endif | ||
|
||
@interface RNExitApp : NSObject <RCTBridgeModule> | ||
@end | ||
|
||
#if RCT_NEW_ARCH_ENABLED | ||
@interface RNExitApp () <NativeRNExitAppSpec> | ||
@end | ||
#endif |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
#import "RNExitApp.h" | ||
|
||
#if RCT_NEW_ARCH_ENABLED | ||
#import <RNExitAppSpec/RNExitAppSpec.h> | ||
#endif | ||
|
||
@implementation RNExitApp | ||
|
||
RCT_EXPORT_MODULE(); | ||
|
||
RCT_EXPORT_METHOD(exitApp) | ||
{ | ||
exit(0); | ||
}; | ||
|
||
# pragma mark - New Architecture | ||
|
||
#if RCT_NEW_ARCH_ENABLED | ||
|
||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||
(const facebook::react::ObjCTurboModule::InitParams &)params | ||
{ | ||
return std::make_shared<facebook::react::NativeRNExitAppSpecJSI>(params); | ||
} | ||
|
||
#endif | ||
|
||
@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