react-native(리액트 네이티브) API - Toast
const React = require('react')
const ReactNative = require('react-native')
const {
StyleSheet, Text, View, ToastAndroid, TouchableWithoutFeedback,
} = ReactNative
export default class ToastExample extends React.Component {
static title = 'Toast Example'
static description =
'Example that demonstrates the use of an Android Toast to provide TouchableWithoutFeedback.'
state = {}
render() {
return(
<View>
<View>
<Text>Simple toast</Text>
<TouchableWithoutFeedback
onPress={() =>
ToastAndroid.show(
'This is a toast with short duration',
ToastAndroid.SHORT,
)
}
>
<Text style={styles.text}>Click me.</Text>
</TouchableWithoutFeedback>
</View>
<View>
<Text>Toast with long duration</Text>
<TouchableWithoutFeedback
onPress={() =>
ToastAndroid.show(
'This is a toast woth long duration',
ToastAndroid.LONG,
)
}
>
<Text style={styles.text}>Click me.</Text>
</TouchableWithoutFeedback>
</View>
<View>
<Text>Toast with top gravity</Text>
<TouchableWithoutFeedback
onPress={() =>
ToastAndroid.showWithGravity(
'This is a toast with top gravity',
ToastAndroid.SHORT,
ToastAndroid.TOP,
)
}
>
<Text style={styles.text}>Click me.</Text>
</TouchableWithoutFeedback>
</View>
<View>
<Text>Toast with center gravity</Text>
<TouchableWithoutFeedback
onPress={() =>
ToastAndroid.showWithGravity(
'This is a toast with center gravity',
ToastAndroid.SHORT,
ToastAndroid.CENTER,
)
}
>
<Text style={styles.text}>Click me.</Text>
</TouchableWithoutFeedback>
</View>
<View>
<Text>Toast with bottom gravity</Text>
<TouchableWithoutFeedback
onPress={() =>
ToastAndroid.showWithGravity(
'This is a toast with bottom gravity',
ToastAndroid.SHORT,
ToastAndroid.BOTTOM,
)
}
>
<Text style={styles.text}>Click me.</Text>
</TouchableWithoutFeedback>
</View>
<View>
<Text>Toast with x offset</Text>
<TouchableWithoutFeedback
onPress={() =>
ToastAndroid.showWithGravityAndOffset(
'This is a toast with x offset',
ToastAndroid.SHORT,
ToastAndroid.CENTER,
150,
0,
)
}
>
<Text style={styles.text}>Click me.</Text>
</TouchableWithoutFeedback>
</View>
<View>
<Text>Toast with y offset</Text>
<TouchableWithoutFeedback
onPress={() =>
ToastAndroid.showWithGravityAndOffset(
'This is a toast with y offset',
ToastAndroid.SHORT,
ToastAndroid.BOTTOM,
0,
150,
)
}
>
<Text style={styles.text}>Click me.</Text>
</TouchableWithoutFeedback>
</View>
</View>
)
}
}
var styles = StyleSheet.create({
text: {
color: 'black',
},
})
module.exports = ToastExample
'프로그래밍(Programming) > 리액트 네이티브(React Native)' 카테고리의 다른 글
react-native(리액트 네이티브) API - Vibration (0) | 2019.01.08 |
---|---|
react-native(리액트 네이티브) API - Transforms (0) | 2019.01.08 |
react-native(리액트 네이티브) API - TimerMixin (0) | 2019.01.08 |
react-native(리액트 네이티브) API - TimePickerAndroid (0) | 2019.01.08 |
react-native(리액트 네이티브) API - Share (0) | 2019.01.08 |