Last active
June 5, 2019 16:11
-
-
Save RoRoGadget/67001d269fe1e4fdce0cabbe8aee612e to your computer and use it in GitHub Desktop.
SwiftUI4RN-TextInput
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { AppRegistry, Text, TextInput, View } from 'react-native'; | |
export default class PizzaTranslator extends Component { | |
constructor(props) { | |
super(props); | |
this.state = {text: ''}; | |
} | |
render() { | |
return ( | |
<View style={{padding: 10}}> | |
<TextInput | |
style={{height: 40}} | |
placeholder="Type here to translate!" | |
onChangeText={(text) => this.setState({text})} | |
/> | |
<Text style={{padding: 10, fontSize: 42}}> | |
{this.state.text.split(' ').map((word) => word && '๐').join(' ')} | |
</Text> | |
</View> | |
); | |
} | |
} | |
// skip this line if using Create React Native App | |
AppRegistry.registerComponent('AwesomeProject', () => PizzaTranslator); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SwiftUI | |
import PlaygroundSupport | |
// https://facebook.github.io/react-native/docs/handling-text-input | |
struct PizzaTranslator: View { | |
@State var text: String = "" | |
var body: some View { | |
VStack { | |
Spacer() | |
TextField($text, placeholder: Text("Type here to translate!")) | |
.frame(height: 40) | |
Spacer() | |
Text(self.text.split(separator: " ").map { (word) in return "๐" }.joined(separator: " ") ) | |
.padding(10) | |
.font(Font.system(size: 42)) | |
Spacer() | |
} | |
} | |
} | |
PlaygroundPage.current.liveView = UIHostingController(rootView: PizzaTranslator()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment