Using button created from SwiftUI in ReactNative

This commit is contained in:
Artur Gurgul 2025-08-03 10:01:13 +02:00
parent 97fb795866
commit 41081b5084
7 changed files with 52 additions and 1 deletions

View file

@ -11,6 +11,7 @@ type CustomButtonProps = {
style?: StyleProp<ViewStyle>
}
const CustomButton = requireNativeComponent<CustomButtonProps>('CustomButton')
const BaseButton = requireNativeComponent<CustomButtonProps>('BaseButton')
export default function App() {
const isDarkMode = useColorScheme() === 'dark'
@ -33,7 +34,8 @@ export default function App() {
<View style={styles.container}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<Text>{message ?? 'Waiting for message...'}</Text>
<CustomButton style={{ width: 200, height: 200 }} />
<CustomButton style={{ height: 200 }} />
<BaseButton style={{ height: 200 }} />
<NewAppScreen templateFileName="App.tsx" />
</View>
);

View file

@ -0,0 +1,16 @@
//
// BaseButton.swift
// RNPlayground
//
// Created by Artur Gurgul on 02/08/2025.
//
import SwiftUI
struct BaseButton: View {
var body: some View {
Button("SwiftUI Button") {
}
}
}

View file

@ -0,0 +1,12 @@
//
// BaseButtonManager.m
// RNPlayground
//
// Created by Artur Gurgul on 02/08/2025.
//
#import <React/RCTViewManager.h>
@interface RCT_EXTERN_MODULE(BaseButtonManager, RCTViewManager)
@end

View file

@ -0,0 +1,21 @@
//
// BaseButtonManager.swift
// RNPlayground
//
// Created by Artur Gurgul on 02/08/2025.
//
import Foundation
import React
import SwiftUI
@objc(BaseButtonManager)
class BaseButtonManager: RCTViewManager {
override func view() -> UIView! {
return UIHostingController(rootView: BaseButton()).view
}
override static func requiresMainQueueSetup() -> Bool {
return true
}
}