forked from expo/react-native-action-sheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionSheetProvider.js
62 lines (54 loc) · 1.87 KB
/
ActionSheetProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react';
import PropTypes from 'prop-types';
import ActionSheet from './ActionSheet';
export default class ActionSheetProvider extends React.Component {
static propTypes = {
textStyle: PropTypes.object,
tintIcons: PropTypes.bool,
tintColor: PropTypes.string,
titleTextStyle: PropTypes.object,
messageTextStyle: PropTypes.object,
showSeparators: PropTypes.bool,
separatorStyle: PropTypes.object,
children: PropTypes.any.isRequired,
};
static childContextTypes = {
showActionSheetWithOptions: PropTypes.func,
};
static defaultProps = {
textStyle: {},
tintIcons: true,
tintColor: null,
titleTextStyle: {},
messageTextStyle: {},
showSeparators: false,
separatorStyle: {},
};
getNextValue = (config, propKey) => config[propKey] !== undefined ? config[propKey] : this.props[propKey];
getNextObject = (config, propKey) => ({...this.props[propKey], ...config[propKey]});
getChildContext() {
return {
showActionSheetWithOptions: (...args) => {
const [config, ...rest] = args;
const nextConfig = {
...config,
textStyle: this.getNextObject(config, 'textStyle'),
tintIcons: this.getNextValue(config, 'tintIcons'),
tintColor: this.getNextValue(config, 'tintColor'),
titleTextStyle: this.getNextObject(config, 'titleTextStyle'),
messageTextStyle: this.getNextObject(config, 'messageTextStyle'),
showSeparators: this.getNextValue(config, 'showSeparators'),
separatorStyle: this.getNextObject(config, 'separatorStyle'),
};
this._actionSheetRef.showActionSheetWithOptions(nextConfig, ...rest);
},
};
}
render() {
return (
<ActionSheet ref={component => (this._actionSheetRef = component)}>
{React.Children.only(this.props.children)}
</ActionSheet>
);
}
}