吐司
Toast 轻提示
Toast可用于显示快速警告或错误消息
为了Toast工作,您需要将最顶层的组件包装在
native-base中。
import { Root } from "native-base";
import { StackNavigator } from "react-navigation";
const AppNavigator = StackNavigator(
{
Page: { screen: Page },
}
);
export default () =>
<Root>
<AppNavigator />
</Root>;
属性:
属性 | 默认值 | 选项 | 描述 |
---|---|---|---|
text | - | string | Text content to be shown in the toast |
textStyle | - | - | Style text content for toast |
buttonText | - | string, blank | Text to be displayed inside the button |
buttonTextStyle | - | - | Style button text for toast |
buttonStyle | - | - | Style button for toast |
position | bottom | top, bottom | Sets position for the toast |
type | - | danger, success, warning | Sets context to the Toast |
duration | 1500 | user defined (integer) | Milliseconds after which Toast disappers |
onClose | - | function | Called just before the toast hides |
Toast with duration
import React, { Component } from "react";
import { Container, Header, Content, Text, Button, Toast } from "native-base";
export default class ToastDuration extends Component {
constructor(props) {
super(props);
this.state = {
showToast: false
};
}
render() {
return (
<Container>
<Header />
<Content padder>
<Button
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay",
duration: 3000
})}
>
<Text>Toast</Text>
</Button>
</Content>
</Container>
);
}
}
Toast 位置
import React, { Component } from "react";
import { Container, Header, Content, Text, Button, Toast } from "native-base";
class ToastPosition extends Component {
constructor(props) {
super(props);
this.state = {
showToast: false
};
}
render() {
return (
<Container>
<Header />
<Content padder>
<Button
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay",
position: "top"
})}
>
<Text>Top Toast</Text>
</Button>
<Button
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay",
position: "bottom"
})}
>
<Text>Bottom Toast</Text>
</Button>
</Content>
</Container>
);
}
}
Toast 类型
import React, { Component } from "react";
import { Container, Header, Content, Text, Button, Toast } from "native-base";
class ToastType extends Component {
constructor(props) {
super(props);
this.state = {
showToast: false
};
}
render() {
return (
<Container>
<Header />
<Content padder>
<Button
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay"
})}
>
<Text>Default Toast</Text>
</Button>
<Button success
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay",
type: "success"
})}
>
<Text>Success Toast</Text>
</Button>
<Button warning
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay",
type: "warning"
})}
>
<Text>Warning Toast</Text>
</Button>
<Button danger
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay",
type: "danger"
})}
>
<Text>Danger Toast</Text>
</Button>
</Content>
</Container>
);
}
}
Toast 文本样式
import React, { Component } from "react";
import { Container, Header, Content, Text, Button, Toast } from "native-base";
export default class ToastText extends Component {
constructor(props) {
super(props);
this.state = {
showToast: false
};
}
render() {
return (
<Container>
<Header />
<Content padder>
<Button
onPress={() =>
Toast.show({
text: "Wrong password!",
textStyle: { color: "yellow" },
buttonText: "Okay"
})
}
>
<Text>Toast</Text>
</Button>
</Content>
</Container>
);
}
}
Toast 按钮样式
import React, { Component } from "react";
import { Container, Header, Content, Text, Button, Toast } from "native-base";
class ToastButton extends Component {
constructor(props) {
super(props);
this.state = {
showToast: false
};
}
render() {
return (
<Container>
<Header />
<Content padder>
<Button
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay",
buttonTextStyle: { color: "#008000" },
buttonStyle: { backgroundColor: "#5cb85c" }
})}
>
<Text>Toast</Text>
</Button>
</Content>
</Container>
);
}
}
Toast 按钮样式
import React, { Component } from "react";
import { Container, Header, Content, Text, Button, Toast } from "native-base";
class ToastButton extends Component {
constructor(props) {
super(props);
this.state = {
showToast: false
};
}
render() {
return (
<Container>
<Header />
<Content padder>
<Button
onPress={() =>
Toast.show({
text: "Wrong password!",
buttonText: "Okay",
buttonTextStyle: { color: "#008000" },
buttonStyle: { backgroundColor: "#5cb85c" }
})}
>
<Text>Toast</Text>
</Button>
</Content>
</Container>
);
}
}