Skip to content

Instantly share code, notes, and snippets.

@RoRoGadget
Last active June 5, 2019 16:11
Show Gist options
  • Save RoRoGadget/67001d269fe1e4fdce0cabbe8aee612e to your computer and use it in GitHub Desktop.
Save RoRoGadget/67001d269fe1e4fdce0cabbe8aee612e to your computer and use it in GitHub Desktop.
SwiftUI4RN-TextInput
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);
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