滑动的卡片
DeckSwiper 滑动的卡片
句法
import React, { Component } from 'react';
import { Image } from 'react-native';
import { Container, Header, View, DeckSwiper, Card, CardItem, Thumbnail, Text, Left, Body, Icon } from 'native-base';
const cards = [
{
text: 'Card One',
name: 'One',
image: require('./img/swiper-1.png'),
},
. . .
];
export default class DeckSwiperExample extends Component {
render() {
return (
<Container>
<Header />
<View>
<DeckSwiper
dataSource={cards}
renderItem={item =>
<Card style={{ elevation: 3 }}>
<CardItem>
<Left>
<Thumbnail source={item.image} />
<Body>
<Text>{item.text}</Text>
<Text note>NativeBase</Text>
</Body>
</Left>
</CardItem>
<CardItem cardBody>
<Image style={{ height: 300, flex: 1 }} source={item.image} />
</CardItem>
<CardItem>
<Icon name="heart" style={{ color: '#ED4A6A' }} />
<Text>{item.name}</Text>
</CardItem>
</Card>
}
/>
</View>
</Container>
);
}
}
属性:
属性 | 默认值 | 选项 | 描述 |
---|---|---|---|
dataSource | - | User | defined object Chunk of data(object) |
renderEmpty | Function | - | Callback that is called when all the cards are swiped and dataSource is empty and returns a component. |
renderItem | Function | - | Callback which takes a chunk of data and returns a component. |
renderTop | Function | - | Callback which takes a chunk of data and returns top layer component. |
renderBottom | Function | - | Callback which takes a chunk of data and returns bottom layer component. |
looping true | boolean | Loop | through the data |
onSwipeRight | Function | - | Callback that is called when the Card is swiped Right |
onSwipeLeft | Function | - | Callback that is called when the Card is swiped Left |
Advanced Deck Swiper 高级滑动的卡片
用法:
import React, { Component } from 'react';
import { Image } from 'react-native';
import { Container, Header, View, DeckSwiper, Card, CardItem, Thumbnail, Text, Left, Body, Icon } from 'native-base';
const cards = [
{
text: 'Card One',
name: 'One',
image: require('./img/swiper-1.png'),
},
. . .
];
export default class DeckSwiperAdvancedExample extends Component {
render() {
return (
<Container>
<Header />
<View>
<DeckSwiper
ref={(c) => this._deckSwiper = c}
dataSource={cards}
renderEmpty={() =>
<View style={{ alignSelf: "center" }}>
<Text>Over</Text>
</View>
renderItem={item =>
<Card style={{ elevation: 3 }}>
<CardItem>
<Left>
<Thumbnail source={item.image} />
<Body>
<Text>{item.text}</Text>
<Text note>NativeBase</Text>
</Body>
</Left>
</CardItem>
<CardItem cardBody>
<Image style={{ height: 300, flex: 1 }} source={item.image} />
</CardItem>
<CardItem>
<Icon name="heart" style={{ color: '#ED4A6A' }} />
<Text>{item.name}</Text>
</CardItem>
</Card>
}
/>
</View>
<View style={{ flexDirection: "row", flex: 1, position: "absolute", bottom: 50, left: 0, right: 0, justifyContent: 'space-between', padding: 15 }}>
<Button iconLeft onPress={() => this._deckSwiper._root.swipeLeft()}>
<Icon name="arrow-back" />
<Text>Swipe Left</Text>
</Button>
<Button iconRight onPress={() => this._deckSwiper._root.swipeRight()}>
<Icon name="arrow-forward" />
<Text>Swipe Right</Text>
</Button>
</View>
</Container>
);
}
}