-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[HybridApp] Add HybridApp turbomodule #57406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6406e0d
c128b40
9e744e5
56b171b
c19b951
73d1b3a
ef370cc
91a78a2
70223f9
ad70f0c
2860064
4b8151d
7aebfe4
f3dbfdf
4803b5f
093d286
9759090
75c6411
2e52297
537ba4e
b46ff0a
3bb959f
04141ef
596a5a1
6282740
bed157d
9a074dd
0871db8
6054969
3a996ad
d293e80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| require "json" | ||
|
|
||
| package = JSON.parse(File.read(File.join(__dir__, "package.json"))) | ||
|
|
||
| Pod::Spec.new do |s| | ||
| s.name = "ReactNativeHybridApp" | ||
| s.version = package["version"] | ||
| s.summary = package["description"] | ||
| s.homepage = package["homepage"] | ||
| s.license = package["license"] | ||
| s.authors = package["author"] | ||
|
|
||
| s.platforms = { :ios => min_ios_version_supported } | ||
| s.source = { :git => ".git", :tag => "#{s.version}" } | ||
|
|
||
| s.source_files = "ios/**/*.{h,m,mm,cpp}" | ||
| s.pod_target_xcconfig = { | ||
| "CLANG_CXX_LANGUAGE_STANDARD" => "c++20", | ||
| } | ||
|
|
||
| install_modules_dependencies(s) | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| buildscript { | ||
| ext.getExtOrDefault = { name -> | ||
| return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeHybridApp_' + name] | ||
| } | ||
|
|
||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| classpath "com.android.tools.build:gradle:8.7.2" | ||
| // noinspection DifferentKotlinGradleVersion | ||
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}" | ||
| } | ||
| } | ||
|
|
||
| apply plugin: "com.android.library" | ||
| apply plugin: "kotlin-android" | ||
| apply plugin: "com.facebook.react" | ||
|
|
||
| def getExtOrIntegerDefault(name) { | ||
| return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeHybridApp_" + name]).toInteger() | ||
| } | ||
|
|
||
| android { | ||
| namespace "com.expensify.reactnativehybridapp" | ||
|
|
||
| compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") | ||
|
|
||
| defaultConfig { | ||
| minSdkVersion getExtOrIntegerDefault("minSdkVersion") | ||
| targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") | ||
| buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true" | ||
| } | ||
|
|
||
| buildFeatures { | ||
| buildConfig true | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| } | ||
| } | ||
|
|
||
| lintOptions { | ||
| disable "GradleCompatible" | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_1_8 | ||
| targetCompatibility JavaVersion.VERSION_1_8 | ||
| } | ||
|
|
||
| sourceSets { | ||
| main { | ||
| java.srcDirs += [ | ||
| "generated/java", | ||
| "generated/jni" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| google() | ||
| } | ||
|
|
||
| def kotlin_version = getExtOrDefault("kotlinVersion") | ||
|
|
||
| dependencies { | ||
| implementation "com.facebook.react:react-android" | ||
| implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
| } | ||
|
|
||
| react { | ||
| jsRootDir = file("../src/") | ||
| libraryName = "ReactNativeHybridApp" | ||
| codegenJavaPackageName = "com.expensify.reactnativehybridapp" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ReactNativeHybridApp_kotlinVersion=2.0.21 | ||
| ReactNativeHybridApp_minSdkVersion=24 | ||
| ReactNativeHybridApp_targetSdkVersion=34 | ||
| ReactNativeHybridApp_compileSdkVersion=35 | ||
| ReactNativeHybridApp_ndkVersion=27.1.12297006 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.expensify.reactnativehybridapp"> | ||
| </manifest> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.expensify.reactnativehybridapp | ||
|
|
||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.module.annotations.ReactModule | ||
| import android.util.Log | ||
|
|
||
| @ReactModule(name = NativeReactNativeHybridAppSpec.NAME) | ||
| class ReactNativeHybridApp(reactContext: ReactApplicationContext) : | ||
| NativeReactNativeHybridAppSpec(reactContext) { | ||
|
|
||
| override fun isHybridApp(): Boolean { | ||
| return false | ||
| } | ||
|
|
||
| override fun closeReactNativeApp(shouldSignOut: Boolean, shouldSetNVP: Boolean) { | ||
| Log.d(NAME, "`closeReactNativeApp` should never be called in standalone `New Expensify` app") | ||
| } | ||
|
|
||
| override fun completeOnboarding(status: Boolean) { | ||
| Log.d(NAME, "`completeOnboarding` should never be called in standalone `New Expensify` app") | ||
| } | ||
|
|
||
| override fun switchAccount( | ||
| newDotCurrentAccountEmail: String?, | ||
| authToken: String?, | ||
| policyID: String?, | ||
| accountID: String? | ||
| ) { | ||
| Log.d(NAME, "`switchAccount` should never be called in standalone `New Expensify` app") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.expensify.reactnativehybridapp | ||
|
|
||
| import com.facebook.react.BaseReactPackage | ||
| import com.facebook.react.bridge.NativeModule | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.module.model.ReactModuleInfo | ||
| import com.facebook.react.module.model.ReactModuleInfoProvider | ||
| import java.util.HashMap | ||
|
|
||
| class ReactNativeHybridAppPackage : BaseReactPackage() { | ||
| override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { | ||
| return if (name == NativeReactNativeHybridAppSpec.NAME) { | ||
| ReactNativeHybridApp(reactContext) | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
| return ReactModuleInfoProvider { | ||
| val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap() | ||
| moduleInfos[NativeReactNativeHybridAppSpec.NAME] = ReactModuleInfo( | ||
| NativeReactNativeHybridAppSpec.NAME, | ||
| NativeReactNativeHybridAppSpec.NAME, | ||
| false, // canOverrideExistingModule | ||
| false, // needsEagerInit | ||
| false, // isCxxModule | ||
| true // isTurboModule | ||
| ) | ||
| moduleInfos | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| #import "RNReactNativeHybridAppSpec/RNReactNativeHybridAppSpec.h" | ||
|
|
||
| @interface ReactNativeHybridApp : NSObject <NativeReactNativeHybridAppSpec> | ||
|
|
||
| @end |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||
| #import "ReactNativeHybridApp.h" | ||||
|
|
||||
| @implementation ReactNativeHybridApp | ||||
| RCT_EXPORT_MODULE() | ||||
|
|
||||
| - (NSNumber *)isHybridApp { | ||||
| return @false; | ||||
| } | ||||
|
|
||||
| - (void)closeReactNativeApp:(BOOL)shouldSignOut shouldSetNVP:(BOOL)shouldSetNVP { | ||||
| NSLog(@"[ReactNativeHybridApp] `closeReactNativeApp` should never be called in standalone `New Expensify` app"); | ||||
| } | ||||
|
|
||||
| - (void)completeOnboarding:(BOOL)status { | ||||
| NSLog(@"[ReactNativeHybridApp] `completeOnboarding` should never be called in standalone `New Expensify` app"); | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| } | ||||
|
|
||||
| - (void)switchAccount:(NSString *)newDotCurrentAccountEmail authToken:(NSString *)authToken policyID:(NSString *)policyID accountID:(NSString *)accountID { | ||||
| NSLog(@"[ReactNativeHybridApp] `switchAccount` should never be called in standalone `New Expensify` app"); | ||||
| } | ||||
|
|
||||
| - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||||
| (const facebook::react::ObjCTurboModule::InitParams &)params | ||||
| { | ||||
| return std::make_shared<facebook::react::NativeReactNativeHybridAppSpecJSI>(params); | ||||
| } | ||||
|
|
||||
| @end | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "@expensify/react-native-hybrid-app", | ||
| "version": "0.0.0", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely NAB, but maybe we could increment the version 😄
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd keep it that way because we have |
||
| "description": "HybridApp", | ||
| "main": "src/index", | ||
| "codegenConfig": { | ||
| "name": "RNReactNativeHybridAppSpec", | ||
| "type": "modules", | ||
| "jsSrcsDir": "src" | ||
| }, | ||
| "author": " <> ()", | ||
|
war-in marked this conversation as resolved.
|
||
| "license": "UNLICENSED", | ||
| "homepage": "#readme", | ||
| "create-react-native-library": { | ||
| "type": "turbo-module", | ||
| "languages": "kotlin-objc", | ||
| "version": "0.48.1" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** | ||
| * @type {import('@react-native-community/cli-types').UserDependencyConfig} | ||
| */ | ||
| module.exports = { | ||
| dependency: { | ||
| platforms: { | ||
| android: { | ||
| cmakeListsPath: 'build/generated/source/codegen/jni/CMakeLists.txt', | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type {TurboModule} from 'react-native'; | ||
| import {TurboModuleRegistry} from 'react-native'; | ||
|
|
||
| // eslint-disable-next-line rulesdir/no-inline-named-export, @typescript-eslint/consistent-type-definitions | ||
| export interface Spec extends TurboModule { | ||
| isHybridApp: () => boolean; | ||
|
war-in marked this conversation as resolved.
|
||
| closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; | ||
| completeOnboarding: (status: boolean) => void; | ||
| switchAccount: (newDotCurrentAccountEmail: string, authToken: string, policyID: string, accountID: string) => void; | ||
| } | ||
|
|
||
| export default TurboModuleRegistry.getEnforcing<Spec>('ReactNativeHybridApp'); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import ReactNativeHybridApp from './NativeReactNativeHybridApp'; | ||
| import type HybridAppModuleType from './types'; | ||
|
|
||
| const HybridAppModule: HybridAppModuleType = { | ||
| isHybridApp() { | ||
| return ReactNativeHybridApp.isHybridApp(); | ||
| }, | ||
| closeReactNativeApp({shouldSignOut, shouldSetNVP}) { | ||
| ReactNativeHybridApp.closeReactNativeApp(shouldSignOut, shouldSetNVP); | ||
| }, | ||
| completeOnboarding({status}) { | ||
| ReactNativeHybridApp.completeOnboarding(status); | ||
| }, | ||
| switchAccount({newDotCurrentAccountEmail, authToken, policyID, accountID}) { | ||
| ReactNativeHybridApp.switchAccount(newDotCurrentAccountEmail, authToken, policyID, accountID); | ||
| }, | ||
| }; | ||
|
|
||
| export default HybridAppModule; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import Log from '@libs/Log'; | ||
| import type HybridAppModuleType from './types'; | ||
|
|
||
| const HybridAppModule: HybridAppModuleType = { | ||
| isHybridApp() { | ||
| return false; | ||
| }, | ||
| closeReactNativeApp() { | ||
| Log.warn('HybridAppModule: `closeReactNativeApp` should never be called on web'); | ||
| }, | ||
| completeOnboarding() { | ||
| Log.warn('HybridAppModule: `completeOnboarding` should never be called on web'); | ||
| }, | ||
| switchAccount() { | ||
| Log.warn('HybridAppModule: `switchAccount` should never be called on web'); | ||
| }, | ||
| }; | ||
|
|
||
| export default HybridAppModule; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| type HybridAppModuleType = { | ||
| isHybridApp: () => boolean; | ||
| closeReactNativeApp: (args: {shouldSignOut: boolean; shouldSetNVP: boolean}) => void; | ||
| completeOnboarding: (args: {status: boolean}) => void; | ||
| switchAccount: (args: {newDotCurrentAccountEmail: string; authToken: string; policyID: string; accountID: string}) => void; | ||
| }; | ||
|
|
||
| export default HybridAppModuleType; |
Uh oh!
There was an error while loading. Please reload this page.