2
A
回答
2
如果您愿意,请按照this guide使用React Native Swipeout。
否则,这里是我的SwipeList和SwipeListRow组件。我部分使用我的图书馆Cairn的造型,但它应该很容易地转换成普通样式表做出反应,如果你愿意这样做的:
SwipeList.js
import React from 'react';
import { Text, ListView } from 'react-native';
import styleContext from 'app/style';
const style = styleContext.extend({
listViewSection: {
paddingVertical: 10,
paddingLeft: 15,
backgroundColor: '$greyDefault'
},
'text.listViewSection': {
color: '$greyMid',
fontSize: 16,
marginLeft: 5
}
});
function SwipeList({ dataSource, renderRow }) {
function renderSectionHeader(sectionData, sectionId) {
return (
<View {...style('listViewSection')}>
<Text {...style('text.listViewSection')}>{sectionId.toUpperCase()}</Text>
</View>
);
}
if (!dataSource.rowIdentities.length) {
return (
<Text>No items found.</Text>
);
}
return (
<ListView
dataSource={dataSource}
automaticallyAdjustContentInsets={false}
directionalLockEnabled
keyboardShouldPersistTaps={false}
keyboardDismissMode={'on-drag'}
renderSectionHeader={renderSectionHeader}
renderRow={renderRow} />
);
}
SwipeList.propTypes = {
dataSource: React.PropTypes.shape({
rowIdentities: React.PropTypes.array.isRequired
}).isRequired,
renderRow: React.PropTypes.func.isRequired
};
export default SwipeList;
SwipeListRow.js
import React from 'react';
import {
View,
Text,
ScrollView,
Animated,
Dimensions
} from 'react-native';
import styleContext from 'app/style';
const { width } = Dimensions.get('window');
const style = styleContext.extend({
swipeMessage: {
position: 'absolute',
top: 0,
height: 75,
justifyContent: 'center',
alignItems: 'center'
},
itemContainer: {
width
}
});
const WHITE = 0;
const GREEN = 1;
const AnimatedScrollView = Animated.createAnimatedComponent(ScrollView);
class SwipeListRow extends React.Component {
constructor(props) {
super(props);
this.state = {
color: new Animated.Value(WHITE)
};
}
animateScroll = (e) => {
const threshold = width/5;
let x = e.nativeEvent.contentOffset.x;
let swiped = null;
x = x * -1;
if (x > -50 && this.swiped !== WHITE) {
swiped = WHITE;
} else if (x < -50 && x > -threshold && this.swiped !== GREEN) {
swiped = GREEN;
}
if (swiped !== null) {
this.swiped = swiped;
Animated.timing(this.state.color, {
toValue: swiped,
duration: 200
}).start();
}
}
takeAction =() => {
if (this.swiped) {
Animated.timing(this.state.color, {
toValue: WHITE,
duration: 200
}).start();
this.props.onSwipe();
}
}
render() {
const { swipeEnabled, swipeMessage, children } = this.props;
const bgColor = this.state.color.interpolate({
inputRange: [
WHITE,
GREEN
],
outputRange: [
'rgb(255, 255, 255)',
'rgb(123, 204, 40)'
]
});
return (
<View>
<AnimatedScrollView
horizontal
directionalLockEnabled
automaticallyAdjustContentInsets={false}
onScroll={this.animateScroll}
scrollEventThrottle={16}
scrollEnabled={swipeEnabled}
onMomentumScrollBegin={this.takeAction}
style={[{ flex: 1 }, { backgroundColor: bgColor }]}>
<View>
<View {...style('itemContainer')}>
{children}
</View>
<View
{...style(
'swipeMessage',
[{ width: width/5, right: -width/5 - 20 }]
)}>
<Text {...style('text.bold text.white')}>{swipeMessage}</Text>
</View>
</View>
</AnimatedScrollView>
</View>
);
}
}
SwipeListRow.propTypes = {
children: React.PropTypes.node.isRequired,
onSwipe: React.PropTypes.func.isRequired,
swipeEnabled: React.PropTypes.bool.isRequired,
swipeMessage: React.PropTypes.string.isRequired
};
export default SwipeListRow;
使用这些组件,现在您只需将所需数据源传递到正常列表视图即可,如ListView component documentation上所述。
<SwipeList
dataSource={dataSource}
renderRow={(item) => (
<SwipeListRow
key={item.id}
swipeMessage={'Delete Item'}
onSwipe={() => deleteItem(item)}
swipeEnabled={true}>
<<< INSERT DISPLAY OF ROW HERE >>>
</SwipeListRow>
)} />
0
相关问题
- 1. 反应原生列表视图
- 2. 反应原生列表视图TouchableHighlight
- 3. 如何给列表视图下拉到刷新功能在android
- 4. 反应原生视频:超表达必须是空或功能
- 5. 反应原生视图层
- 6. 反应原生视图
- 7. 列表视图刷卡内viewflipper
- 8. 反应原生导航选项卡注销功能
- 9. 反应原生滚动视图禁用拉刷新
- 10. 在反应原生列表视图中搜索大数据
- 11. 如何呼吁刷卡功能?
- 12. 如何刷新列表视图当列表视图
- 13. 如何反向viewpager刷卡
- 14. 如何刷新动态列表视图?
- 15. 如何刷新Android的列表视图
- 16. 如何使原生Web视图消失?
- 17. 如何在列表视图中使用搜索功能
- 18. 可滚动选项卡视图中的动态选项卡反应原生
- 19. jquery移动刷卡功能
- 20. Javascript |反应原生地图功能无法正常工作
- 21. 反应原生。无法在地图功能中设置参考
- 22. 如何通过视图刷卡在containerView
- 23. 在列表视图中呈现两个项目(图像)在原生反应
- 24. 刷卡按钮点击时原生
- 25. 原生反应:如何在网格视图中划分五行?
- 26. 如何传递视图/组件的原生反应数组?
- 27. 反应原生视频与反应原生导航工作
- 28. 列表视图刷新android
- 29. Android列表视图刷新
- 30. 刷新Android列表视图
当我[只包含一小段代码](http://stackoverflow.com/help/mcve)时,我似乎得到了更快,更好,更多的答案。可能是因为其他人复制/粘贴/修改比从头开始编写示例要容易得多,程序员通常可以阅读代码,以便快速查看问题,而不管写出问题的语言如何。 –