@callstack/react-native-brownfield 0.1.0 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -1
- package/ReactNativeBrownfield.podspec +10 -3
- package/android/build.gradle +89 -16
- package/android/gradle.properties +5 -0
- package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeBrownfield.kt +82 -15
- package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeBrownfieldModule.kt +22 -21
- package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeBrownfieldPackage.kt +9 -9
- package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeFragment.kt +139 -145
- package/ios/ReactNativeBrownfield.swift +119 -0
- package/ios/ReactNativeBrownfieldModule.m +8 -11
- package/ios/ReactNativeBrownfieldModule.swift +18 -0
- package/ios/ReactNativeView.swift +42 -0
- package/ios/ReactNativeViewController.swift +66 -0
- package/lib/commonjs/RNBrownfieldSpec.js +9 -0
- package/lib/commonjs/RNBrownfieldSpec.js.map +1 -0
- package/lib/commonjs/index.js +6 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/module/RNBrownfieldSpec.js +5 -0
- package/lib/module/RNBrownfieldSpec.js.map +1 -0
- package/lib/module/index.js +8 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/typescript/src/RNBrownfieldSpec.d.ts +20 -0
- package/lib/typescript/src/RNBrownfieldSpec.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +32 -27
- package/src/RNBrownfieldSpec.ts +23 -0
- package/src/index.ts +6 -7
- package/android/src/main/java/com/callstack/reactnativebrownfield/ReactNativeActivity.kt +0 -188
- package/ios/ReactNativeBrownfield.h +0 -24
- package/ios/ReactNativeBrownfield.m +0 -82
- package/ios/ReactNativeBrownfieldNotifications.h +0 -4
- package/ios/ReactNativeBrownfieldNotifications.m +0 -4
- package/ios/ReactNativeViewController.h +0 -15
- package/ios/ReactNativeViewController.m +0 -66
package/lib/module/index.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import ReactNativeBrownfieldModule from './RNBrownfieldSpec';
|
|
2
5
|
const ReactNativeBrownfield = {
|
|
3
6
|
popToNative: animated => {
|
|
4
7
|
if (Platform.OS === 'ios') {
|
|
5
|
-
|
|
8
|
+
ReactNativeBrownfieldModule.popToNative(animated);
|
|
6
9
|
} else if (Platform.OS === 'android') {
|
|
7
|
-
|
|
10
|
+
ReactNativeBrownfieldModule.popToNative();
|
|
8
11
|
} else {
|
|
9
12
|
console.warn('Not implemented: popToNative');
|
|
10
13
|
}
|
|
11
14
|
},
|
|
12
15
|
setNativeBackGestureAndButtonEnabled: enabled => {
|
|
13
16
|
if (Platform.OS === 'ios') {
|
|
14
|
-
|
|
17
|
+
ReactNativeBrownfieldModule.setPopGestureRecognizerEnabled(enabled);
|
|
15
18
|
} else if (Platform.OS === 'android') {
|
|
16
|
-
|
|
19
|
+
ReactNativeBrownfieldModule.setHardwareBackButtonEnabled(enabled);
|
|
17
20
|
} else {
|
|
18
21
|
console.warn('Not implemented: setNativeGesturesAndButtonsEnabled');
|
|
19
22
|
}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Platform","ReactNativeBrownfieldModule","ReactNativeBrownfield","popToNative","animated","OS","console","warn","setNativeBackGestureAndButtonEnabled","enabled","setPopGestureRecognizerEnabled","setHardwareBackButtonEnabled"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,OAAOC,2BAA2B,MAAM,oBAAoB;AAE5D,MAAMC,qBAAqB,GAAG;EAC5BC,WAAW,EAAGC,QAAkB,IAAW;IACzC,IAAIJ,QAAQ,CAACK,EAAE,KAAK,KAAK,EAAE;MACzBJ,2BAA2B,CAACE,WAAW,CAACC,QAAQ,CAAC;IACnD,CAAC,MAAM,IAAIJ,QAAQ,CAACK,EAAE,KAAK,SAAS,EAAE;MACpCJ,2BAA2B,CAACE,WAAW,CAAC,CAAC;IAC3C,CAAC,MAAM;MACLG,OAAO,CAACC,IAAI,CAAC,8BAA8B,CAAC;IAC9C;EACF,CAAC;EAEDC,oCAAoC,EAAGC,OAAgB,IAAW;IAChE,IAAIT,QAAQ,CAACK,EAAE,KAAK,KAAK,EAAE;MACzBJ,2BAA2B,CAACS,8BAA8B,CAACD,OAAO,CAAC;IACrE,CAAC,MAAM,IAAIT,QAAQ,CAACK,EAAE,KAAK,SAAS,EAAE;MACpCJ,2BAA2B,CAACU,4BAA4B,CAACF,OAAO,CAAC;IACnE,CAAC,MAAM;MACLH,OAAO,CAACC,IAAI,CAAC,qDAAqD,CAAC;IACrE;EACF;AACF,CAAC;AAED,eAAeL,qBAAqB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
|
+
/**
|
|
4
|
+
* Navigate back to the native part of the application.
|
|
5
|
+
*/
|
|
6
|
+
popToNative(animated?: boolean): void;
|
|
7
|
+
/**
|
|
8
|
+
* Enable or disable the iOS swipe back gesture.
|
|
9
|
+
* @platform ios
|
|
10
|
+
*/
|
|
11
|
+
setPopGestureRecognizerEnabled(enabled: boolean): void;
|
|
12
|
+
/**
|
|
13
|
+
* Enable or disable the Android hardware back button.
|
|
14
|
+
* @platform android
|
|
15
|
+
*/
|
|
16
|
+
setHardwareBackButtonEnabled(enabled: boolean): void;
|
|
17
|
+
}
|
|
18
|
+
declare const _default: Spec;
|
|
19
|
+
export default _default;
|
|
20
|
+
//# sourceMappingURL=RNBrownfieldSpec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RNBrownfieldSpec.d.ts","sourceRoot":"","sources":["../../../src/RNBrownfieldSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;OAEG;IACH,WAAW,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEtC;;;OAGG;IACH,8BAA8B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvD;;;OAGG;IACH,4BAA4B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACtD;;AAED,wBAA+E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,qBAAqB;6BACA,OAAO,KAAG,IAAI;oDAUS,OAAO,KAAG,IAAI;CAS/D,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@callstack/react-native-brownfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Michal Chudziak <mike.chudziak@callstack.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"types": "lib/typescript/src/index.d.ts",
|
|
14
14
|
"react-native": "src/index",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"start": "react-native start --reset-cache",
|
|
17
16
|
"lint": "eslint . --fix",
|
|
18
17
|
"typecheck": "tsc --noEmit",
|
|
19
18
|
"release": "release-it",
|
|
20
|
-
"prepare": "bob build"
|
|
19
|
+
"prepare": "bob build",
|
|
20
|
+
"brownfield:plugin:publish:local": "bash ./gradle-plugins/publish-to-maven-local.sh"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"react-native-brownfield",
|
|
@@ -47,41 +47,35 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"resolutions": {
|
|
50
|
-
"@types/react": "
|
|
50
|
+
"@types/react": "19.0.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": "*",
|
|
54
54
|
"react-native": "*"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@babel/core": "^7.
|
|
58
|
-
"@babel/preset-env": "^7.
|
|
59
|
-
"@babel/runtime": "^7.
|
|
60
|
-
"@react-native/babel-preset": "0.
|
|
61
|
-
"@react-native/eslint-config": "0.
|
|
62
|
-
"@react-native/
|
|
63
|
-
"@react-native/typescript-config": "0.74.84",
|
|
64
|
-
"@react-navigation/native": "^6.1.17",
|
|
65
|
-
"@react-navigation/native-stack": "^6.9.17",
|
|
57
|
+
"@babel/core": "^7.25.2",
|
|
58
|
+
"@babel/preset-env": "^7.25.3",
|
|
59
|
+
"@babel/runtime": "^7.25.0",
|
|
60
|
+
"@react-native/babel-preset": "0.78.0",
|
|
61
|
+
"@react-native/eslint-config": "0.78.0",
|
|
62
|
+
"@react-native/typescript-config": "0.78.0",
|
|
66
63
|
"@release-it/conventional-changelog": "^5.0.0",
|
|
67
|
-
"@types/
|
|
68
|
-
"@types/react
|
|
69
|
-
"
|
|
64
|
+
"@types/jest": "^29.5.13",
|
|
65
|
+
"@types/react": "^19.0.0",
|
|
66
|
+
"@types/react-test-renderer": "^19.0.0",
|
|
70
67
|
"babel-plugin-module-resolver": "5.0.0",
|
|
71
68
|
"eslint": "^8.19.0",
|
|
69
|
+
"eslint-config-prettier": "^9.1.0",
|
|
72
70
|
"eslint-plugin-prettier": "^5.1.3",
|
|
73
71
|
"jest": "^29.6.3",
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"react": "
|
|
77
|
-
"react-native": "0.
|
|
78
|
-
"react-
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"react-native-screens": "^3.31.1",
|
|
82
|
-
"react-test-renderer": "18.2.0",
|
|
83
|
-
"release-it": "^15.0.0",
|
|
84
|
-
"typescript": "^5.0.4"
|
|
72
|
+
"prettier": "^3.5.3",
|
|
73
|
+
"react": "19.0.0",
|
|
74
|
+
"react-native": "0.78.0",
|
|
75
|
+
"react-native-builder-bob": "^0.37.0",
|
|
76
|
+
"react-test-renderer": "19.0.0",
|
|
77
|
+
"release-it": "^18.1.2",
|
|
78
|
+
"typescript": "5.0.4"
|
|
85
79
|
},
|
|
86
80
|
"release-it": {
|
|
87
81
|
"git": {
|
|
@@ -106,6 +100,9 @@
|
|
|
106
100
|
"@react-native",
|
|
107
101
|
"prettier"
|
|
108
102
|
],
|
|
103
|
+
"plugins": [
|
|
104
|
+
"prettier"
|
|
105
|
+
],
|
|
109
106
|
"rules": {
|
|
110
107
|
"prettier/prettier": [
|
|
111
108
|
"error",
|
|
@@ -119,6 +116,14 @@
|
|
|
119
116
|
]
|
|
120
117
|
}
|
|
121
118
|
},
|
|
119
|
+
"codegenConfig": {
|
|
120
|
+
"name": "RNBrownfieldSpec",
|
|
121
|
+
"type": "modules",
|
|
122
|
+
"jsSrcsDir": "src",
|
|
123
|
+
"android": {
|
|
124
|
+
"javaPackageName": "com.callstack.reactnativebrownfield"
|
|
125
|
+
}
|
|
126
|
+
},
|
|
122
127
|
"prettier": {
|
|
123
128
|
"quoteProps": "consistent",
|
|
124
129
|
"singleQuote": true,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
/**
|
|
6
|
+
* Navigate back to the native part of the application.
|
|
7
|
+
*/
|
|
8
|
+
popToNative(animated?: boolean): void;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Enable or disable the iOS swipe back gesture.
|
|
12
|
+
* @platform ios
|
|
13
|
+
*/
|
|
14
|
+
setPopGestureRecognizerEnabled(enabled: boolean): void;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Enable or disable the Android hardware back button.
|
|
18
|
+
* @platform android
|
|
19
|
+
*/
|
|
20
|
+
setHardwareBackButtonEnabled(enabled: boolean): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('ReactNativeBrownfield');
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import ReactNativeBrownfieldModule from './RNBrownfieldSpec';
|
|
2
3
|
|
|
3
4
|
const ReactNativeBrownfield = {
|
|
4
5
|
popToNative: (animated?: boolean): void => {
|
|
5
6
|
if (Platform.OS === 'ios') {
|
|
6
|
-
|
|
7
|
+
ReactNativeBrownfieldModule.popToNative(animated);
|
|
7
8
|
} else if (Platform.OS === 'android') {
|
|
8
|
-
|
|
9
|
+
ReactNativeBrownfieldModule.popToNative();
|
|
9
10
|
} else {
|
|
10
11
|
console.warn('Not implemented: popToNative');
|
|
11
12
|
}
|
|
@@ -13,11 +14,9 @@ const ReactNativeBrownfield = {
|
|
|
13
14
|
|
|
14
15
|
setNativeBackGestureAndButtonEnabled: (enabled: boolean): void => {
|
|
15
16
|
if (Platform.OS === 'ios') {
|
|
16
|
-
|
|
17
|
-
enabled,
|
|
18
|
-
);
|
|
17
|
+
ReactNativeBrownfieldModule.setPopGestureRecognizerEnabled(enabled);
|
|
19
18
|
} else if (Platform.OS === 'android') {
|
|
20
|
-
|
|
19
|
+
ReactNativeBrownfieldModule.setHardwareBackButtonEnabled(enabled);
|
|
21
20
|
} else {
|
|
22
21
|
console.warn('Not implemented: setNativeGesturesAndButtonsEnabled');
|
|
23
22
|
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
package com.callstack.reactnativebrownfield
|
|
2
|
-
|
|
3
|
-
import android.annotation.TargetApi
|
|
4
|
-
import android.content.Context
|
|
5
|
-
import android.content.Intent
|
|
6
|
-
import android.os.Build
|
|
7
|
-
import android.os.Bundle
|
|
8
|
-
import android.view.KeyEvent
|
|
9
|
-
import com.facebook.infer.annotation.Assertions
|
|
10
|
-
import com.facebook.react.ReactActivity
|
|
11
|
-
import com.facebook.react.ReactRootView
|
|
12
|
-
import com.facebook.react.devsupport.DoubleTapReloadRecognizer
|
|
13
|
-
import com.facebook.react.modules.core.PermissionListener
|
|
14
|
-
import com.facebook.react.bridge.Callback
|
|
15
|
-
import com.facebook.react.bridge.ReadableMap
|
|
16
|
-
import com.facebook.react.common.DebugServerException
|
|
17
|
-
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
|
|
18
|
-
import com.facebook.react.modules.core.PermissionAwareActivity
|
|
19
|
-
|
|
20
|
-
private const val MODULE_NAME = "com.callstack.reactnativebrownfield.ACTIVITY_MODULE_NAME"
|
|
21
|
-
private const val INITIAL_PROPS = "com.callstack.reactnativebrownfield.ACTIVITY_INITIAL_PROPS"
|
|
22
|
-
|
|
23
|
-
class ReactNativeActivity : ReactActivity(), DefaultHardwareBackBtnHandler, PermissionAwareActivity {
|
|
24
|
-
private var reactRootView: ReactRootView? = null
|
|
25
|
-
private lateinit var doubleTapReloadRecognizer: DoubleTapReloadRecognizer
|
|
26
|
-
private lateinit var permissionsCallback: Callback
|
|
27
|
-
private var permissionListener: PermissionListener? = null
|
|
28
|
-
|
|
29
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
|
30
|
-
super.onCreate(savedInstanceState)
|
|
31
|
-
|
|
32
|
-
val moduleName = intent.getStringExtra(MODULE_NAME)
|
|
33
|
-
val initialProps = intent.getBundleExtra(INITIAL_PROPS)
|
|
34
|
-
|
|
35
|
-
reactRootView = ReactRootView(this)
|
|
36
|
-
reactRootView?.startReactApplication(
|
|
37
|
-
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager,
|
|
38
|
-
moduleName,
|
|
39
|
-
initialProps
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
supportActionBar?.hide()
|
|
43
|
-
setContentView(reactRootView)
|
|
44
|
-
doubleTapReloadRecognizer = DoubleTapReloadRecognizer()
|
|
45
|
-
checkPackagerConnection()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
override fun onDestroy() {
|
|
49
|
-
super.onDestroy()
|
|
50
|
-
reactRootView?.unmountReactApplication()
|
|
51
|
-
reactRootView = null
|
|
52
|
-
|
|
53
|
-
if (ReactNativeBrownfield.shared.reactNativeHost.hasInstance()) {
|
|
54
|
-
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager?.onHostDestroy(this)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
59
|
-
super.onActivityResult(requestCode, resultCode, data)
|
|
60
|
-
if (ReactNativeBrownfield.shared.reactNativeHost.hasInstance()) {
|
|
61
|
-
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager?.onActivityResult(this, requestCode, resultCode, data)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
|
66
|
-
if (ReactNativeBrownfield.shared.reactNativeHost.hasInstance()
|
|
67
|
-
&& ReactNativeBrownfield.shared.reactNativeHost.useDeveloperSupport
|
|
68
|
-
&& keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD
|
|
69
|
-
) {
|
|
70
|
-
event.startTracking()
|
|
71
|
-
return true
|
|
72
|
-
}
|
|
73
|
-
return false
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
|
|
77
|
-
if(keyCode == KeyEvent.KEYCODE_BACK) {
|
|
78
|
-
onBackPressed()
|
|
79
|
-
return true
|
|
80
|
-
}
|
|
81
|
-
if (ReactNativeBrownfield.shared.reactNativeHost.hasInstance()
|
|
82
|
-
&& ReactNativeBrownfield.shared.reactNativeHost.useDeveloperSupport) {
|
|
83
|
-
if (keyCode == KeyEvent.KEYCODE_MENU) {
|
|
84
|
-
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager.showDevOptionsDialog()
|
|
85
|
-
return true
|
|
86
|
-
}
|
|
87
|
-
val didDoubleTapR = this.currentFocus?.let {
|
|
88
|
-
Assertions.assertNotNull(doubleTapReloadRecognizer)
|
|
89
|
-
.didDoubleTapR(keyCode, it)
|
|
90
|
-
}
|
|
91
|
-
if (didDoubleTapR == true) {
|
|
92
|
-
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager.devSupportManager.handleReloadJS()
|
|
93
|
-
return true
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return false
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
override fun onKeyLongPress(keyCode: Int, event: KeyEvent): Boolean {
|
|
100
|
-
if (ReactNativeBrownfield.shared.reactNativeHost.hasInstance()
|
|
101
|
-
&& ReactNativeBrownfield.shared.reactNativeHost.useDeveloperSupport
|
|
102
|
-
&& keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD
|
|
103
|
-
) {
|
|
104
|
-
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager.showDevOptionsDialog()
|
|
105
|
-
return true
|
|
106
|
-
}
|
|
107
|
-
return false
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
override fun onBackPressed() {
|
|
111
|
-
if(ReactNativeBrownfieldModule.shouldPopToNative) {
|
|
112
|
-
super.invokeDefaultOnBackPressed()
|
|
113
|
-
} else if (ReactNativeBrownfield.shared.reactNativeHost.hasInstance()) {
|
|
114
|
-
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager.onBackPressed()
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
override fun invokeDefaultOnBackPressed() {
|
|
119
|
-
super.onBackPressed()
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
@TargetApi(Build.VERSION_CODES.M)
|
|
123
|
-
override fun requestPermissions(
|
|
124
|
-
permissions: Array<String>,
|
|
125
|
-
requestCode: Int,
|
|
126
|
-
listener: PermissionListener
|
|
127
|
-
) {
|
|
128
|
-
permissionListener = listener
|
|
129
|
-
this.requestPermissions(permissions, requestCode)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
override fun onRequestPermissionsResult(
|
|
133
|
-
requestCode: Int,
|
|
134
|
-
permissions: Array<String>,
|
|
135
|
-
grantResults: IntArray
|
|
136
|
-
) {
|
|
137
|
-
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
138
|
-
permissionsCallback = Callback {
|
|
139
|
-
if (permissionListener != null) {
|
|
140
|
-
permissionListener?.onRequestPermissionsResult(
|
|
141
|
-
requestCode,
|
|
142
|
-
permissions,
|
|
143
|
-
grantResults
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
permissionListener = null
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
private fun checkPackagerConnection() {
|
|
152
|
-
if (ReactNativeBrownfield.shared.reactNativeHost.hasInstance() && ReactNativeBrownfield.shared.reactNativeHost.useDeveloperSupport) {
|
|
153
|
-
val devSupportManager =
|
|
154
|
-
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager.devSupportManager
|
|
155
|
-
val url = devSupportManager.sourceUrl
|
|
156
|
-
devSupportManager?.isPackagerRunning { isRunning ->
|
|
157
|
-
if (!isRunning) {
|
|
158
|
-
val error = Error()
|
|
159
|
-
val message = DebugServerException.makeGeneric(url, "Could not connect to development server.", "URL: $url", error).message
|
|
160
|
-
devSupportManager.showNewJavaError(message, error)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
companion object {
|
|
167
|
-
@JvmStatic
|
|
168
|
-
@JvmOverloads
|
|
169
|
-
fun createReactActivityIntent(context: Context, moduleName: String, initialProps: Bundle? = null): Intent {
|
|
170
|
-
val intent = Intent(context, ReactNativeActivity::class.java)
|
|
171
|
-
intent.putExtra(MODULE_NAME, moduleName)
|
|
172
|
-
if (initialProps != null) {
|
|
173
|
-
intent.putExtra(INITIAL_PROPS, initialProps)
|
|
174
|
-
}
|
|
175
|
-
return intent
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
@JvmStatic
|
|
179
|
-
fun createReactActivityIntent(context: Context, moduleName: String, initialProps: HashMap<String, *>): Intent {
|
|
180
|
-
return createReactActivityIntent(context, moduleName, PropsBundle.fromHashMap(initialProps))
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
@JvmStatic
|
|
184
|
-
fun createReactActivityIntent(context: Context, moduleName: String, initialProps: ReadableMap): Intent {
|
|
185
|
-
return createReactActivityIntent(context, moduleName, initialProps.toHashMap())
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import <React/RCTBridge.h>
|
|
3
|
-
#import <React/RCTBridgeDelegate.h>
|
|
4
|
-
|
|
5
|
-
NS_ASSUME_NONNULL_BEGIN
|
|
6
|
-
|
|
7
|
-
@interface ReactNativeBrownfield : NSObject<RCTBridgeDelegate> {
|
|
8
|
-
void (^_onBundleLoaded)(void);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@property (nonatomic, copy) NSString *entryFile;
|
|
12
|
-
@property (nonatomic, copy, nullable) NSString *fallbackResource;
|
|
13
|
-
@property (nonatomic, copy) NSString *bundlePath;
|
|
14
|
-
@property (nonatomic) RCTBridge *bridge;
|
|
15
|
-
|
|
16
|
-
+(ReactNativeBrownfield*)shared;
|
|
17
|
-
|
|
18
|
-
-(void)startReactNative;
|
|
19
|
-
-(void)startReactNative:(void(^)(void))onBundleLoaded;
|
|
20
|
-
-(void)startReactNative:(void(^)(void))onBundleLoaded launchOptions:(NSDictionary *)launchOptions;
|
|
21
|
-
|
|
22
|
-
@end
|
|
23
|
-
|
|
24
|
-
NS_ASSUME_NONNULL_END
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import <React/RCTBundleURLProvider.h>
|
|
3
|
-
|
|
4
|
-
#import "ReactNativeBrownfield.h"
|
|
5
|
-
|
|
6
|
-
@implementation ReactNativeBrownfield
|
|
7
|
-
|
|
8
|
-
@synthesize entryFile = _entryFile;
|
|
9
|
-
@synthesize fallbackResource = _fallbackResource;
|
|
10
|
-
@synthesize bundlePath = _bundlePath;
|
|
11
|
-
@synthesize bridge;
|
|
12
|
-
|
|
13
|
-
+ (ReactNativeBrownfield*)shared {
|
|
14
|
-
static ReactNativeBrownfield *sharedBridgeManager = nil;
|
|
15
|
-
|
|
16
|
-
static dispatch_once_t onceToken;
|
|
17
|
-
dispatch_once(&onceToken, ^{
|
|
18
|
-
sharedBridgeManager = [self new];
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return sharedBridgeManager;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
- (id)init {
|
|
25
|
-
if (self = [super init]) {
|
|
26
|
-
_entryFile = @"index";
|
|
27
|
-
_fallbackResource = nil;
|
|
28
|
-
_bundlePath = @"main.jsbundle";
|
|
29
|
-
}
|
|
30
|
-
return self;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
- (void)startReactNative {
|
|
34
|
-
[self startReactNative:nil];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
- (void)startReactNative:(void(^)(void))onBundleLoaded {
|
|
38
|
-
[self startReactNative:onBundleLoaded launchOptions:nil];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
- (void)startReactNative:(void(^)(void))onBundleLoaded launchOptions:(NSDictionary *)launchOptions {
|
|
42
|
-
if (bridge != nil) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
|
|
47
|
-
|
|
48
|
-
if (onBundleLoaded != nil) {
|
|
49
|
-
_onBundleLoaded = [onBundleLoaded copy];
|
|
50
|
-
|
|
51
|
-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jsLoaded:) name:RCTJavaScriptDidLoadNotification object:nil];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
- (void)jsLoaded:(NSNotification*)notification {
|
|
56
|
-
_onBundleLoaded();
|
|
57
|
-
_onBundleLoaded = nil;
|
|
58
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
#pragma mark - RCTBridgeDelegate Methods
|
|
62
|
-
|
|
63
|
-
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
|
|
64
|
-
#if DEBUG
|
|
65
|
-
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:_entryFile];
|
|
66
|
-
#else
|
|
67
|
-
NSArray<NSString *> *resourceURLComponents = [_bundlePath componentsSeparatedByString:@"."];
|
|
68
|
-
NSRange withoutLast;
|
|
69
|
-
|
|
70
|
-
withoutLast.location = 0;
|
|
71
|
-
withoutLast.length = [resourceURLComponents count] - 2;
|
|
72
|
-
|
|
73
|
-
NSArray<NSString *> *resourceURLComponentsWithoutExtension = [resourceURLComponents subarrayWithRange:withoutLast];
|
|
74
|
-
|
|
75
|
-
return [[NSBundle mainBundle]
|
|
76
|
-
URLForResource:[resourceURLComponentsWithoutExtension componentsJoinedByString:@""]
|
|
77
|
-
withExtension:resourceURLComponents[resourceURLComponents.count - 1]
|
|
78
|
-
];
|
|
79
|
-
#endif
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
@end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#import <UIKit/UIKit.h>
|
|
2
|
-
|
|
3
|
-
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
-
|
|
5
|
-
@interface ReactNativeViewController : UIViewController
|
|
6
|
-
|
|
7
|
-
@property (nonatomic, copy) NSString *moduleName;
|
|
8
|
-
@property (nonatomic, copy, nullable) NSDictionary *initialProperties;
|
|
9
|
-
|
|
10
|
-
-(instancetype)initWithModuleName:(NSString *)moduleName;
|
|
11
|
-
-(instancetype)initWithModuleName:(NSString *)moduleName andInitialProperties:(NSDictionary*)initialProperties;
|
|
12
|
-
|
|
13
|
-
@end
|
|
14
|
-
|
|
15
|
-
NS_ASSUME_NONNULL_END
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#import "ReactNativeViewController.h"
|
|
2
|
-
#import <React/RCTRootView.h>
|
|
3
|
-
#import <React/RCTBridge.h>
|
|
4
|
-
#import "ReactNativeBrownfield.h"
|
|
5
|
-
#import "ReactNativeBrownfieldNotifications.h"
|
|
6
|
-
|
|
7
|
-
@implementation ReactNativeViewController
|
|
8
|
-
|
|
9
|
-
@synthesize moduleName = _moduleName;
|
|
10
|
-
@synthesize initialProperties = _initialProperties;
|
|
11
|
-
|
|
12
|
-
-(instancetype)initWithModuleName:(NSString *)moduleName {
|
|
13
|
-
return [self initWithModuleName:moduleName andInitialProperties:nil];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
-(instancetype)initWithModuleName:(NSString *)moduleName
|
|
17
|
-
andInitialProperties:(NSDictionary*)initialProperties {
|
|
18
|
-
self = [super init];
|
|
19
|
-
_moduleName = moduleName;
|
|
20
|
-
_initialProperties = initialProperties;
|
|
21
|
-
|
|
22
|
-
return self;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
-(void)viewDidLoad {
|
|
26
|
-
RCTBridge *bridge = [[ReactNativeBrownfield shared] bridge];
|
|
27
|
-
if (bridge == nil) {
|
|
28
|
-
NSLog(@"Error: You need to start React Native in order to use ReactNativeViewController, make sure to run [[BridgeManager shared] startReactNative] before instantiating it.");
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (_moduleName) {
|
|
33
|
-
RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:_moduleName initialProperties:_initialProperties];
|
|
34
|
-
self.view = reactView;
|
|
35
|
-
|
|
36
|
-
[[NSNotificationCenter defaultCenter]
|
|
37
|
-
addObserver:self selector:@selector(togglePopGestureRecognizer:)
|
|
38
|
-
name:TogglePopGestureRecognizerNotification object:nil];
|
|
39
|
-
[[NSNotificationCenter defaultCenter]
|
|
40
|
-
addObserver:self selector:@selector(popToNative:)
|
|
41
|
-
name:PopToNativeNotification object:nil];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
- (void)dealloc {
|
|
46
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
- (void)togglePopGestureRecognizer:(NSNotification*)notification {
|
|
50
|
-
NSDictionary *userInfo = notification.userInfo;
|
|
51
|
-
BOOL enabled = [[userInfo objectForKey:@"enabled"] boolValue];
|
|
52
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
53
|
-
self.navigationController.interactivePopGestureRecognizer.enabled = enabled;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
- (void)popToNative:(NSNotification*)notification {
|
|
58
|
-
NSDictionary *userInfo = notification.userInfo;
|
|
59
|
-
BOOL animated = [[userInfo objectForKey:@"animated"] boolValue];
|
|
60
|
-
|
|
61
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
62
|
-
[self.navigationController popViewControllerAnimated:animated];
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@end
|