2016-05-12 01:01:17 +00:00
|
|
|
/**
|
2017-03-24 21:36:07 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-05-12 01:01:17 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-05-12 01:01:17 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2016-05-12 01:01:17 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2016-05-12 01:01:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const React = require('React');
|
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const View = require('View');
|
|
|
|
|
2017-03-24 07:22:57 +00:00
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
|
|
|
|
2016-06-07 18:55:38 +00:00
|
|
|
/**
|
|
|
|
* A thin wrapper around standard quick action buttons that can, if the user
|
|
|
|
* chooses, be used with SwipeableListView. Sample usage is as follows, in the
|
|
|
|
* renderQuickActions callback:
|
|
|
|
*
|
|
|
|
* <SwipeableQuickActions>
|
|
|
|
* <SwipeableQuickActionButton {..props} />
|
|
|
|
* <SwipeableQuickActionButton {..props} />
|
|
|
|
* </SwipeableQuickActions>
|
|
|
|
*/
|
2017-08-18 01:36:54 +00:00
|
|
|
class SwipeableQuickActions extends React.Component<{style?: $FlowFixMe}> {
|
2016-07-26 08:00:02 +00:00
|
|
|
static propTypes = {
|
2017-03-24 07:22:57 +00:00
|
|
|
style: ViewPropTypes.style,
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2016-05-12 01:01:17 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
render(): React.Node {
|
2016-07-26 08:00:02 +00:00
|
|
|
// $FlowFixMe found when converting React.createClass to ES6
|
2016-05-12 01:01:17 +00:00
|
|
|
const children = this.props.children;
|
|
|
|
let buttons = [];
|
|
|
|
|
|
|
|
// Multiple children
|
|
|
|
if (children instanceof Array) {
|
2017-02-02 13:14:20 +00:00
|
|
|
for (let i = 0; i < children.length; i++) {
|
2016-05-12 01:01:17 +00:00
|
|
|
buttons.push(children[i]);
|
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
// $FlowFixMe found when converting React.createClass to ES6
|
2018-05-11 02:06:46 +00:00
|
|
|
if (i < this.props.children.length - 1) {
|
|
|
|
// Not last button
|
2016-05-12 01:01:17 +00:00
|
|
|
buttons.push(<View key={i} style={styles.divider} />);
|
|
|
|
}
|
|
|
|
}
|
2018-05-11 02:06:46 +00:00
|
|
|
} else {
|
|
|
|
// 1 child
|
2016-05-12 01:01:17 +00:00
|
|
|
buttons = children;
|
|
|
|
}
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
return <View style={[styles.background, this.props.style]}>{buttons}</View>;
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-12 01:01:17 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
background: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
},
|
|
|
|
divider: {
|
|
|
|
width: 4,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = SwipeableQuickActions;
|