Using button created from SwiftUI in ReactNative
This commit is contained in:
parent
97fb795866
commit
41081b5084
7 changed files with 52 additions and 1 deletions
4
App.tsx
4
App.tsx
|
@ -11,6 +11,7 @@ type CustomButtonProps = {
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
}
|
}
|
||||||
const CustomButton = requireNativeComponent<CustomButtonProps>('CustomButton')
|
const CustomButton = requireNativeComponent<CustomButtonProps>('CustomButton')
|
||||||
|
const BaseButton = requireNativeComponent<CustomButtonProps>('BaseButton')
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const isDarkMode = useColorScheme() === 'dark'
|
const isDarkMode = useColorScheme() === 'dark'
|
||||||
|
@ -33,7 +34,8 @@ export default function App() {
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
|
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
|
||||||
<Text>{message ?? 'Waiting for message...'}</Text>
|
<Text>{message ?? 'Waiting for message...'}</Text>
|
||||||
<CustomButton style={{ width: 200, height: 200 }} />
|
<CustomButton style={{ height: 200 }} />
|
||||||
|
<BaseButton style={{ height: 200 }} />
|
||||||
<NewAppScreen templateFileName="App.tsx" />
|
<NewAppScreen templateFileName="App.tsx" />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
16
ios/Native/Application/BaseButton/BaseButton.swift
Normal file
16
ios/Native/Application/BaseButton/BaseButton.swift
Normal 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") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
ios/Native/Application/BaseButton/BaseButtonManager.m
Normal file
12
ios/Native/Application/BaseButton/BaseButtonManager.m
Normal 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
|
21
ios/Native/Application/BaseButton/BaseButtonManager.swift
Normal file
21
ios/Native/Application/BaseButton/BaseButtonManager.swift
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue