Skip to content

Instantly share code, notes, and snippets.

@RoRoGadget
Last active June 8, 2019 12:41
Show Gist options
  • Save RoRoGadget/6c0e741e616bafd8a19b8b8c12436f46 to your computer and use it in GitHub Desktop.
Save RoRoGadget/6c0e741e616bafd8a19b8b8c12436f46 to your computer and use it in GitHub Desktop.
SwiftUI4RN-TouchInput
import React, { Component } from 'react';
import { Alert, AppRegistry, Button, StyleSheet, View } from 'react-native';
export default class ButtonBasics extends Component {
_onPressButton() {
Alert.alert('You tapped the button!')
}
render() {
return (
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button
onPress={this._onPressButton}
title="Press Me"
/>
</View>
<View style={styles.buttonContainer}>
<Button
onPress={this._onPressButton}
title="Press Me"
color="#841584"
/>
</View>
<View style={styles.alternativeLayoutButtonContainer}>
<Button
onPress={this._onPressButton}
title="This looks great!"
/>
<Button
onPress={this._onPressButton}
title="OK!"
color="#841584"
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
buttonContainer: {
margin: 20
},
alternativeLayoutButtonContainer: {
margin: 20,
flexDirection: 'row',
justifyContent: 'space-between'
}
});
// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => ButtonBasics);
import UIKit
import SwiftUI
import PlaygroundSupport
// https://facebook.github.io/react-native/docs/handling-touches
struct ButtonBasics: View {
@State var text: String = ""
@State var showAlert: Bool = false
var body: some View {
VStack(spacing: 20) {
Button(action: {
self.onPressButton()
}) {
Text("Press Me")
}
Button(action: {
self.onPressButton()
}) {
Text("Press Me")
}.accentColor(Color(red: 132 / 255.0, green: 21 / 255.0, blue: 132 / 255.0))
HStack {
Button(action: {
self.onPressButton()
}) {
Text("This looks great!")
}
Button(action: {
self.onPressButton()
}) {
Text("Ok!")
}.accentColor(Color(red: 132 / 255.0, green: 21 / 255.0, blue: 132 / 255.0))
}.padding(20.0)
}.padding(20.0)
.presentation($showAlert) { () -> Alert in
Alert(title: Text("You tapped the button!"),
message: nil,
dismissButton: Alert.Button.default(Text("Ok")))
}
}
func onPressButton() {
self.showAlert = true
}
}
PlaygroundPage.current.liveView = UIHostingController(rootView: ButtonBasics())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment