Skip to content

Commit dc89737

Browse files
authored
fix: prevent name shadowing, make it proper TM (#103)
* fix: prevent name shadowing, make it a proper turbo module * feat: proper turbo module for Android * fix: rename to ReactBrownfield
1 parent 7e75bae commit dc89737

16 files changed

+175
-86
lines changed

ReactBrownfield.podspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'json'
2+
3+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4+
5+
Pod::Spec.new do |spec|
6+
spec.name = "ReactBrownfield"
7+
spec.version = package['version']
8+
spec.summary = package['description']
9+
spec.license = package['license']
10+
11+
spec.authors = package['author']
12+
spec.homepage = package['homepage']
13+
spec.platform = :ios, "14.0"
14+
15+
spec.module_name = "ReactBrownfield"
16+
spec.source = { :git => "[email protected]:callstack/react-native-brownfield.git", :tag => "#{spec.version}" }
17+
spec.source_files = "ios/**/*.{h,m,mm,swift}"
18+
spec.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
19+
20+
spec.dependency 'ReactAppDependencyProvider'
21+
install_modules_dependencies(spec)
22+
end

ReactNativeBrownfield.podspec

Lines changed: 0 additions & 27 deletions
This file was deleted.

android/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ android {
8484
sourceCompatibility JavaVersion.VERSION_1_8
8585
targetCompatibility JavaVersion.VERSION_1_8
8686
}
87+
88+
sourceSets {
89+
main {
90+
if (isNewArchitectureEnabled()) {
91+
java.srcDirs += [
92+
"src/newarch",
93+
// Codegen specs
94+
"generated/java",
95+
"generated/jni"
96+
]
97+
} else {
98+
java.srcDirs += ["src/oldarch"]
99+
}
100+
}
101+
}
87102
}
88103

89104
repositories {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.callstack.reactnativebrownfield
2+
3+
import com.facebook.react.bridge.ReactApplicationContext
4+
import com.facebook.react.bridge.ReactMethod
5+
6+
class ReactNativeBrownfieldModule(reactContext: ReactApplicationContext) :
7+
NativeReactNativeBrownfieldModuleSpec(reactContext) {
8+
companion object {
9+
var shouldPopToNative: Boolean = false
10+
}
11+
12+
@ReactMethod
13+
override fun popToNative(animated: Boolean) {
14+
shouldPopToNative = true
15+
onBackPressed()
16+
}
17+
18+
@ReactMethod
19+
override fun setPopGestureRecognizerEnabled(enabled: Boolean) {
20+
shouldPopToNative = enabled
21+
}
22+
23+
@ReactMethod
24+
override fun setHardwareBackButtonEnabled(enabled: Boolean) {
25+
shouldPopToNative = enabled
26+
}
27+
28+
private fun onBackPressed() {
29+
reactApplicationContext.currentActivity?.runOnUiThread {
30+
reactApplicationContext.currentActivity?.onBackPressed()
31+
}
32+
}
33+
34+
override fun getName(): String {
35+
return "ReactNativeBrownfield"
36+
}
37+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ class ReactNativeBrownfieldModule(reactContext: ReactApplicationContext) :
1111
}
1212

1313
@ReactMethod
14-
fun popToNative() {
14+
fun popToNative(animated: Boolean) {
1515
shouldPopToNative = true
1616
onBackPressed()
1717
}
1818

19+
@ReactMethod
20+
fun setPopGestureRecognizerEnabled(enabled: Boolean) {
21+
shouldPopToNative = enabled
22+
}
23+
1924
@ReactMethod
2025
fun setHardwareBackButtonEnabled(isFirstRoute: Boolean) {
2126
shouldPopToNative = isFirstRoute

docs/SWIFT.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ React Native Brownfield provides first-class support for Swift.
99
You can import the object from:
1010

1111
```swift
12-
import ReactNativeBrownfield
12+
import ReactBrownfield
1313
```
1414

1515
---
@@ -80,7 +80,7 @@ React Native Brownfield supports two main approaches for initialization:
8080

8181
```swift
8282
import UIKit
83-
import ReactNativeBrownfield
83+
import ReactBrownfield
8484

8585
class AppDelegate: UIResponder, UIApplicationDelegate {
8686
var window: UIWindow?
@@ -98,7 +98,7 @@ To present a React Native view in a UIKit app, use `ReactNativeViewController`:
9898

9999
```swift
100100
import UIKit
101-
import ReactNativeBrownfield
101+
import ReactBrownfield
102102

103103
class ViewController: UIViewController {
104104
@IBAction func openReactNativeScreen(_ sender: UIButton) {
@@ -113,7 +113,7 @@ class ViewController: UIViewController {
113113

114114
```swift
115115
import SwiftUI
116-
import ReactNativeBrownfield
116+
import ReactBrownfield
117117

118118
@main
119119
struct MyApp: App {
@@ -135,7 +135,7 @@ To display React Native views in SwiftUI, use the provided `ReactNativeView` com
135135

136136
```swift
137137
import SwiftUI
138-
import ReactNativeBrownfield
138+
import ReactBrownfield
139139

140140
struct ContentView: View {
141141
var body: some View {
@@ -167,7 +167,7 @@ A view controller that's rendering React Native view within its bounds. It autom
167167
You can import it from:
168168

169169
```swift
170-
import ReactNativeBrownfield
170+
import ReactBrownfield
171171
```
172172

173173
---
@@ -200,7 +200,7 @@ A SwiftUI view that wraps the `ReactNativeViewController`, making it easy to int
200200
You can import it from:
201201

202202
```swift
203-
import ReactNativeBrownfield
203+
import ReactBrownfield
204204
```
205205

206206
---

example/react-native.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require("path");
1+
const path = require('path');
22
const pkg = require('../package.json');
33

44
module.exports = {
@@ -7,8 +7,8 @@ module.exports = {
77
automaticPodsInstallation: true,
88
},
99
android: {
10-
sourceDir: './kotlin'
11-
}
10+
sourceDir: './kotlin',
11+
},
1212
},
1313
dependencies: {
1414
[pkg.name]: {

example/swift/App.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import SwiftUI
2-
import ReactNativeBrownfield
2+
import ReactBrownfield
33

44
@main
55
struct MyApp: App {

example/swift/Podfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ target 'SwiftExample' do
2727
react_native_post_install(
2828
installer,
2929
config[:reactNativePath],
30-
:mac_catalyst_enabled => false
30+
:mac_catalyst_enabled => false,
31+
:ccache_enabled => true
3132
)
3233
end
3334
end

example/swift/Podfile.lock

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,28 @@ PODS:
15271527
- React-jsi (= 0.78.0)
15281528
- ReactAppDependencyProvider (0.78.0):
15291529
- ReactCodegen
1530+
- ReactBrownfield (1.0.0-rc.0):
1531+
- DoubleConversion
1532+
- glog
1533+
- hermes-engine
1534+
- RCT-Folly (= 2024.11.18.00)
1535+
- RCTRequired
1536+
- RCTTypeSafety
1537+
- React-Core
1538+
- React-debug
1539+
- React-Fabric
1540+
- React-featureflags
1541+
- React-graphics
1542+
- React-ImageManager
1543+
- React-NativeModulesApple
1544+
- React-RCTFabric
1545+
- React-rendererdebug
1546+
- React-utils
1547+
- ReactAppDependencyProvider
1548+
- ReactCodegen
1549+
- ReactCommon/turbomodule/bridging
1550+
- ReactCommon/turbomodule/core
1551+
- Yoga
15301552
- ReactCodegen (0.78.0):
15311553
- DoubleConversion
15321554
- glog
@@ -1591,28 +1613,6 @@ PODS:
15911613
- React-logger (= 0.78.0)
15921614
- React-perflogger (= 0.78.0)
15931615
- React-utils (= 0.78.0)
1594-
- ReactNativeBrownfield (0.1.0):
1595-
- DoubleConversion
1596-
- glog
1597-
- hermes-engine
1598-
- RCT-Folly (= 2024.11.18.00)
1599-
- RCTRequired
1600-
- RCTTypeSafety
1601-
- React-Core
1602-
- React-debug
1603-
- React-Fabric
1604-
- React-featureflags
1605-
- React-graphics
1606-
- React-ImageManager
1607-
- React-NativeModulesApple
1608-
- React-RCTFabric
1609-
- React-rendererdebug
1610-
- React-utils
1611-
- ReactAppDependencyProvider
1612-
- ReactCodegen
1613-
- ReactCommon/turbomodule/bridging
1614-
- ReactCommon/turbomodule/core
1615-
- Yoga
16161616
- RNScreens (4.9.1):
16171617
- DoubleConversion
16181618
- glog
@@ -1728,9 +1728,9 @@ DEPENDENCIES:
17281728
- React-timing (from `../node_modules/react-native/ReactCommon/react/timing`)
17291729
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
17301730
- ReactAppDependencyProvider (from `build/generated/ios`)
1731+
- ReactBrownfield (from `../..`)
17311732
- ReactCodegen (from `build/generated/ios`)
17321733
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
1733-
- ReactNativeBrownfield (from `../..`)
17341734
- RNScreens (from `../node_modules/react-native-screens`)
17351735
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
17361736

@@ -1868,12 +1868,12 @@ EXTERNAL SOURCES:
18681868
:path: "../node_modules/react-native/ReactCommon/react/utils"
18691869
ReactAppDependencyProvider:
18701870
:path: build/generated/ios
1871+
ReactBrownfield:
1872+
:path: "../.."
18711873
ReactCodegen:
18721874
:path: build/generated/ios
18731875
ReactCommon:
18741876
:path: "../node_modules/react-native/ReactCommon"
1875-
ReactNativeBrownfield:
1876-
:path: "../.."
18771877
RNScreens:
18781878
:path: "../node_modules/react-native-screens"
18791879
Yoga:
@@ -1944,13 +1944,13 @@ SPEC CHECKSUMS:
19441944
React-timing: bb220a53a795ed57976a4855c521f3de2f298fe5
19451945
React-utils: 3b054aaebe658fc710a8d239d0e4b9fd3e0b78f9
19461946
ReactAppDependencyProvider: a1fb08dfdc7ebc387b2e54cfc9decd283ed821d8
1947+
ReactBrownfield: e05f198df083698ed9942ace80fd90da6e9298de
19471948
ReactCodegen: 008c319179d681a6a00966edfc67fda68f9fbb2e
19481949
ReactCommon: 0c097b53f03d6bf166edbcd0915da32f3015dd90
1949-
ReactNativeBrownfield: 4cbb58bb8076bf4e4c4a9769ada50f6c6db1f6a7
19501950
RNScreens: 0d4cb9afe052607ad0aa71f645a88bb7c7f2e64c
19511951
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
19521952
Yoga: afd04ff05ebe0121a00c468a8a3c8080221cb14c
19531953

1954-
PODFILE CHECKSUM: 0e2d5a1ac40562245e67fac5c121a808e048368b
1954+
PODFILE CHECKSUM: b5dc5f822e98018cbffd7384516e146bba9f6d99
19551955

19561956
COCOAPODS: 1.15.2

0 commit comments

Comments
 (0)