react-native/RNTester/js/SwipeableFlatListExample.js
Himanshu Soni b32029f346 remove createReactClass from RNTester/js/SwipeableFlatListExample.js (#21613)
Summary:
Related to #21581 .
Removed createReactClass from the RNTester/js/SwipeableFlatListExample.js

Test Plan
-----

 - [x]  npm run prettier
- [x]  npm run flow-check-ios
- [x]  npm run flow-check-android
- [x]  Run RNTester app, go to SwipeableFlatList component, everything works.

Release Notes
--------

[GENERAL] [ENHANCEMENT] [RNTester/js/SwipeableFlatListExample.js] - remove createReactClass dependency
Pull Request resolved: https://github.com/facebook/react-native/pull/21613

Differential Revision: D10275399

Pulled By: RSNara

fbshipit-source-id: 63030ca7da979a3d25bb94d52d4fd59994504aa3
2018-10-09 17:16:24 -07:00

145 lines
3.2 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const React = require('react');
const ReactNative = require('react-native');
const {
Image,
SwipeableFlatList,
TouchableHighlight,
StyleSheet,
Text,
View,
Alert,
} = ReactNative;
const RNTesterPage = require('./RNTesterPage');
import type {RNTesterProps} from 'RNTesterTypes';
const data = [
{
key: 'like',
icon: require('./Thumbnails/like.png'),
data: 'Like!',
},
{
key: 'heart',
icon: require('./Thumbnails/heart.png'),
data: 'Heart!',
},
{
key: 'party',
icon: require('./Thumbnails/party.png'),
data: 'Party!',
},
];
class SwipeableFlatListExample extends React.Component<RNTesterProps> {
static title = '<SwipeableFlatList>';
static description = 'Performant, scrollable, swipeable list of data.';
render() {
return (
<RNTesterPage
title={this.props.navigator ? null : '<SwipeableListView>'}
noSpacer={true}
noScroll={true}>
<SwipeableFlatList
data={data}
bounceFirstRowOnMount={true}
maxSwipeDistance={160}
renderItem={this._renderItem.bind(this)}
renderQuickActions={this._renderQuickActions.bind(this)}
/>
</RNTesterPage>
);
}
_renderItem({item}): ?React.Element<any> {
return (
<View style={styles.row}>
<Image style={styles.rowIcon} source={item.icon} />
<View style={styles.rowData}>
<Text style={styles.rowDataText}>{item.data}</Text>
</View>
</View>
);
}
_renderQuickActions({item}: Object): ?React.Element<any> {
return (
<View style={styles.actionsContainer}>
<TouchableHighlight
style={styles.actionButton}
onPress={() => {
Alert.alert(
'Tips',
'You could do something with this edit action!',
);
}}>
<Text style={styles.actionButtonText}>Edit</Text>
</TouchableHighlight>
<TouchableHighlight
style={[styles.actionButton, styles.actionButtonDestructive]}
onPress={() => {
Alert.alert(
'Tips',
'You could do something with this remove action!',
);
}}>
<Text style={styles.actionButtonText}>Remove</Text>
</TouchableHighlight>
</View>
);
}
}
var styles = StyleSheet.create({
row: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
padding: 10,
backgroundColor: '#F6F6F6',
},
rowIcon: {
width: 64,
height: 64,
marginRight: 20,
},
rowData: {
flex: 1,
},
rowDataText: {
fontSize: 24,
},
actionsContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems: 'center',
},
actionButton: {
padding: 10,
width: 80,
backgroundColor: '#999999',
},
actionButtonDestructive: {
backgroundColor: '#FF0000',
},
actionButtonText: {
textAlign: 'center',
},
});
module.exports = SwipeableFlatListExample;