Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ReactBrownfield.podspec
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 |spec|
spec.name = "ReactBrownfield"
spec.version = package['version']
spec.summary = package['description']
spec.license = package['license']

spec.authors = package['author']
spec.homepage = package['homepage']
spec.platform = :ios, "14.0"

spec.module_name = "ReactBrownfield"
spec.source = { :git => "git@github.com:callstack/react-native-brownfield.git", :tag => "#{spec.version}" }
spec.source_files = "ios/**/*.{h,m,mm,swift}"
spec.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }

spec.dependency 'ReactAppDependencyProvider'
install_modules_dependencies(spec)
end
27 changes: 0 additions & 27 deletions ReactNativeBrownfield.podspec

This file was deleted.

15 changes: 15 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"src/newarch",
// Codegen specs
"generated/java",
"generated/jni"
]
} else {
java.srcDirs += ["src/oldarch"]
}
}
}
}

repositories {
Expand Down
37 changes: 37 additions & 0 deletions android/src/newarch/ReactNativeBrownfieldModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.callstack.reactnativebrownfield

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod

class ReactNativeBrownfieldModule(reactContext: ReactApplicationContext) :
NativeReactNativeBrownfieldModuleSpec(reactContext) {
companion object {
var shouldPopToNative: Boolean = false
}

@ReactMethod
override fun popToNative(animated: Boolean) {
shouldPopToNative = true
onBackPressed()
}

@ReactMethod
override fun setPopGestureRecognizerEnabled(enabled: Boolean) {
shouldPopToNative = enabled
}

@ReactMethod
override fun setHardwareBackButtonEnabled(enabled: Boolean) {
shouldPopToNative = enabled
}

private fun onBackPressed() {
reactApplicationContext.currentActivity?.runOnUiThread {
reactApplicationContext.currentActivity?.onBackPressed()
}
}

override fun getName(): String {
return "ReactNativeBrownfield"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ class ReactNativeBrownfieldModule(reactContext: ReactApplicationContext) :
}

@ReactMethod
fun popToNative() {
fun popToNative(animated: Boolean) {
shouldPopToNative = true
onBackPressed()
}

@ReactMethod
fun setPopGestureRecognizerEnabled(enabled: Boolean) {
shouldPopToNative = enabled
}

@ReactMethod
fun setHardwareBackButtonEnabled(isFirstRoute: Boolean) {
shouldPopToNative = isFirstRoute
Expand Down
14 changes: 7 additions & 7 deletions docs/SWIFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ React Native Brownfield provides first-class support for Swift.
You can import the object from:

```swift
import ReactNativeBrownfield
import ReactBrownfield
```

---
Expand Down Expand Up @@ -80,7 +80,7 @@ React Native Brownfield supports two main approaches for initialization:

```swift
import UIKit
import ReactNativeBrownfield
import ReactBrownfield

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

```swift
import UIKit
import ReactNativeBrownfield
import ReactBrownfield

class ViewController: UIViewController {
@IBAction func openReactNativeScreen(_ sender: UIButton) {
Expand All @@ -113,7 +113,7 @@ class ViewController: UIViewController {

```swift
import SwiftUI
import ReactNativeBrownfield
import ReactBrownfield

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

```swift
import SwiftUI
import ReactNativeBrownfield
import ReactBrownfield

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

```swift
import ReactNativeBrownfield
import ReactBrownfield
```

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

```swift
import ReactNativeBrownfield
import ReactBrownfield
```

---
Expand Down
6 changes: 3 additions & 3 deletions example/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require("path");
const path = require('path');
const pkg = require('../package.json');

module.exports = {
Expand All @@ -7,8 +7,8 @@ module.exports = {
automaticPodsInstallation: true,
},
android: {
sourceDir: './kotlin'
}
sourceDir: './kotlin',
},
},
dependencies: {
[pkg.name]: {
Expand Down
2 changes: 1 addition & 1 deletion example/swift/App.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SwiftUI
import ReactNativeBrownfield
import ReactBrownfield

@main
struct MyApp: App {
Expand Down
3 changes: 2 additions & 1 deletion example/swift/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ target 'SwiftExample' do
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false
:mac_catalyst_enabled => false,
:ccache_enabled => true
)
end
end
54 changes: 27 additions & 27 deletions example/swift/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,28 @@ PODS:
- React-jsi (= 0.78.0)
- ReactAppDependencyProvider (0.78.0):
- ReactCodegen
- ReactBrownfield (1.0.0-rc.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.11.18.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactAppDependencyProvider
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- ReactCodegen (0.78.0):
- DoubleConversion
- glog
Expand Down Expand Up @@ -1591,28 +1613,6 @@ PODS:
- React-logger (= 0.78.0)
- React-perflogger (= 0.78.0)
- React-utils (= 0.78.0)
- ReactNativeBrownfield (0.1.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.11.18.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactAppDependencyProvider
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- RNScreens (4.9.1):
- DoubleConversion
- glog
Expand Down Expand Up @@ -1728,9 +1728,9 @@ DEPENDENCIES:
- React-timing (from `../node_modules/react-native/ReactCommon/react/timing`)
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactAppDependencyProvider (from `build/generated/ios`)
- ReactBrownfield (from `../..`)
- ReactCodegen (from `build/generated/ios`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- ReactNativeBrownfield (from `../..`)
- RNScreens (from `../node_modules/react-native-screens`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -1868,12 +1868,12 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/react/utils"
ReactAppDependencyProvider:
:path: build/generated/ios
ReactBrownfield:
:path: "../.."
ReactCodegen:
:path: build/generated/ios
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
ReactNativeBrownfield:
:path: "../.."
RNScreens:
:path: "../node_modules/react-native-screens"
Yoga:
Expand Down Expand Up @@ -1944,13 +1944,13 @@ SPEC CHECKSUMS:
React-timing: bb220a53a795ed57976a4855c521f3de2f298fe5
React-utils: 3b054aaebe658fc710a8d239d0e4b9fd3e0b78f9
ReactAppDependencyProvider: a1fb08dfdc7ebc387b2e54cfc9decd283ed821d8
ReactBrownfield: e05f198df083698ed9942ace80fd90da6e9298de
ReactCodegen: 008c319179d681a6a00966edfc67fda68f9fbb2e
ReactCommon: 0c097b53f03d6bf166edbcd0915da32f3015dd90
ReactNativeBrownfield: 4cbb58bb8076bf4e4c4a9769ada50f6c6db1f6a7
RNScreens: 0d4cb9afe052607ad0aa71f645a88bb7c7f2e64c
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: afd04ff05ebe0121a00c468a8a3c8080221cb14c

PODFILE CHECKSUM: 0e2d5a1ac40562245e67fac5c121a808e048368b
PODFILE CHECKSUM: b5dc5f822e98018cbffd7384516e146bba9f6d99

COCOAPODS: 1.15.2
9 changes: 7 additions & 2 deletions ios/ReactNativeBrownfieldModule.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#import <React/RCTBridgeModule.h>
#ifdef __cplusplus

@interface ReactNativeBrownfieldModule : NSObject <RCTBridgeModule>
#import <React-RCTAppDelegate/RCTDefaultReactNativeFactoryDelegate.h>
#import <ReactNativeBrownfield/ReactNativeBrownfield.h>

@interface ReactNativeBrownfieldModule : NSObject <NativeReactNativeBrownfieldModuleSpec>
@end

#endif
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#import "ReactNativeBrownfieldModule.h"

#if __has_include("ReactNativeBrownfield/ReactNativeBrownfield-Swift.h")
#import "ReactNativeBrownfield/ReactNativeBrownfield-Swift.h"
#if __has_include("ReactBrownfield/ReactBrownfield-Swift.h")
#import "ReactBrownfield/ReactBrownfield-Swift.h"
#else
#import "ReactNativeBrownfield-Swift.h"
#import "ReactBrownfield-Swift.h"
#endif

@implementation ReactNativeBrownfieldModule
Expand All @@ -18,4 +18,8 @@ @implementation ReactNativeBrownfieldModule
[ReactNativeBrownfieldModuleImpl popToNativeWithAnimated:animated];
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
return std::make_shared<facebook::react::NativeReactNativeBrownfieldModuleSpecJSI>(params);
}

@end
9 changes: 5 additions & 4 deletions ios/ReactNativeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ import SwiftUI
struct ReactNativeViewRepresentable: UIViewControllerRepresentable {
var moduleName: String
var initialProperties: [String: Any] = [:]

func makeUIViewController(context: Context) -> UIViewController {
return ReactNativeViewController(moduleName: moduleName)
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}

/**
Exposes React Native view to SwiftUI.
Supports pop to native when using SwiftUI's NavigationView or NavigationStack.
*/
@available(iOS 15.0, *)
public struct ReactNativeView: View {
@Environment(\.dismiss) var dismiss
var moduleName: String
var initialProperties: [String: Any] = [:]

public init(moduleName: String, initialProperties: [String : Any] = [:]) {
self.moduleName = moduleName
self.initialProperties = initialProperties
}

public var body: some View {
ReactNativeViewRepresentable(
moduleName: moduleName,
Expand Down
Loading
Loading