@shoutem/ui 7.1.0-beta.4 → 7.1.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,183 +1,69 @@
1
- import React, { PureComponent } from 'react';
2
- import { Animated, Dimensions, TouchableOpacity } from 'react-native';
3
- import autoBindReact from 'auto-bind/react';
1
+ import React, { useEffect, useMemo, useRef } from 'react';
2
+ import ActionSheetNative from 'react-native-actions-sheet';
4
3
  import _ from 'lodash';
5
4
  import PropTypes from 'prop-types';
6
5
  import { connectStyle } from '@shoutem/theme';
7
- import { IPHONE_X_HOME_INDICATOR_PADDING } from '../../const';
8
- import { Device } from '../../helpers';
9
6
  import { View } from '../View';
10
7
  import ActionSheetOption, { optionPropType } from './ActionSheetOption';
11
8
 
12
- const { height: windowHeight } = Dimensions.get('window');
13
-
14
- function getContentOffset(contentHeight = windowHeight) {
15
- if (Device.isIphoneXR || Device.isIphoneX) {
16
- return contentHeight + IPHONE_X_HOME_INDICATOR_PADDING;
17
- }
18
-
19
- return contentHeight;
20
- }
21
-
22
- const AnimatedTouchable = Animated.createAnimatedComponent(TouchableOpacity);
23
-
24
- class ActionSheet extends PureComponent {
25
- static getDerivedStateFromProps(props, state) {
26
- const { active } = props;
27
- const { visible } = state;
28
-
29
- if (active !== visible) {
30
- return { visible: active };
9
+ const ActionSheet = ({
10
+ active = false,
11
+ cancelOptions = undefined,
12
+ confirmOptions = undefined,
13
+ style,
14
+ onDismiss = undefined,
15
+ ...otherProps
16
+ }) => {
17
+ const actionSheetRef = useRef(null);
18
+
19
+ const hasConfirmOptions = useMemo(() => !_.isEmpty(confirmOptions), [
20
+ confirmOptions,
21
+ ]);
22
+ const hasCancelOptions = useMemo(() => !_.isEmpty(cancelOptions), [
23
+ cancelOptions,
24
+ ]);
25
+
26
+ useEffect(() => {
27
+ if (active) {
28
+ actionSheetRef.current?.show();
29
+ } else {
30
+ actionSheetRef.current?.hide();
31
31
  }
32
-
33
- return null;
34
- }
35
-
36
- constructor(props) {
37
- super(props);
38
-
39
- autoBindReact(this);
40
-
41
- this.state = {
42
- opacity: new Animated.Value(0),
43
- yPos: new Animated.Value(0),
44
- visible: false,
45
- };
46
- }
47
-
48
- componentDidUpdate(prevProps) {
49
- const { active } = this.props;
50
- const { active: prevActive } = prevProps;
51
-
52
- if (active && !prevActive) {
53
- this.handleEntryAnimation();
54
- }
55
-
56
- if (!active && prevActive) {
57
- this.handleExitAnimation();
58
- }
59
- }
60
-
61
- hideComponent() {
62
- this.setState({ visible: false });
63
- }
64
-
65
- handleContentLayout(event) {
66
- const height = _.get(event, 'nativeEvent.layout.height', 0);
67
-
68
- this.setState({ height });
69
- }
70
-
71
- handleEntryAnimation() {
72
- const { yPos, opacity } = this.state;
73
-
74
- const toValue = 1;
75
-
76
- Animated.parallel([
77
- Animated.spring(yPos, {
78
- toValue,
79
- useNativeDriver: true,
80
- }),
81
- Animated.timing(opacity, {
82
- toValue,
83
- useNativeDriver: false,
84
- }),
85
- ]).start();
86
- }
87
-
88
- handleExitAnimation() {
89
- const { yPos, opacity } = this.state;
90
-
91
- const toValue = 0;
92
-
93
- Animated.parallel([
94
- Animated.spring(yPos, {
95
- toValue,
96
- useNativeDriver: true,
97
- }),
98
- Animated.timing(opacity, {
99
- toValue,
100
- delay: 100,
101
- duration: 150,
102
- useNativeDriver: false,
103
- }),
104
- ]).start(this.hideComponent);
105
- }
106
-
107
- handleInactiveAreaPress() {
108
- const { onDismiss } = this.props;
109
-
110
- if (onDismiss) {
111
- onDismiss();
112
- }
113
- }
114
-
115
- render() {
116
- const { confirmOptions, cancelOptions, style } = this.props;
117
- const { opacity, yPos, visible, height } = this.state;
118
-
119
- const hasConfirmOptions = !_.isEmpty(confirmOptions);
120
- const hasCancelOptions = !_.isEmpty(cancelOptions);
121
-
122
- if (!visible || (!hasConfirmOptions && !hasCancelOptions)) {
123
- return null;
124
- }
125
-
126
- return (
127
- <AnimatedTouchable
128
- activeOpacity={1}
129
- onPress={this.handleInactiveAreaPress}
130
- style={[
131
- style.container,
132
- {
133
- backgroundColor: opacity.interpolate({
134
- inputRange: [0, 1],
135
- outputRange: ['rgba(0, 0, 0, 0)', 'rgba(0, 0, 0, 0.3)'],
136
- }),
137
- },
138
- ]}
139
- >
140
- <Animated.View
141
- onLayout={this.handleContentLayout}
142
- style={[
143
- style.contentContainer,
144
- {
145
- transform: [
146
- {
147
- translateY: yPos.interpolate({
148
- inputRange: [0, 1],
149
- outputRange: [getContentOffset(height), 0],
150
- }),
151
- },
152
- ],
153
- },
154
- ]}
155
- >
156
- {hasConfirmOptions && (
32
+ }, [active]);
33
+
34
+ return (
35
+ <ActionSheetNative
36
+ gestureEnabled
37
+ ref={actionSheetRef}
38
+ onClose={onDismiss}
39
+ containerStyle={style.container}
40
+ {...otherProps}
41
+ >
42
+ <View style={style.contentContainer}>
43
+ {hasConfirmOptions && (
44
+ <View style={style.segmentContainer}>
45
+ {_.map(confirmOptions, option => (
46
+ <ActionSheetOption key={option.title} option={option} />
47
+ ))}
48
+ </View>
49
+ )}
50
+ {hasCancelOptions && (
51
+ <View styleName="md-gutter-top">
157
52
  <View style={style.segmentContainer}>
158
- {_.map(confirmOptions, option => (
159
- <ActionSheetOption key={option.title} option={option} />
53
+ {_.map(cancelOptions, option => (
54
+ <ActionSheetOption
55
+ key={option.title}
56
+ cancelOption
57
+ option={option}
58
+ />
160
59
  ))}
161
60
  </View>
162
- )}
163
- {hasCancelOptions && (
164
- <View styleName="md-gutter-top">
165
- <View style={style.segmentContainer}>
166
- {_.map(cancelOptions, option => (
167
- <ActionSheetOption
168
- key={option.title}
169
- cancelOption
170
- option={option}
171
- />
172
- ))}
173
- </View>
174
- </View>
175
- )}
176
- </Animated.View>
177
- </AnimatedTouchable>
178
- );
179
- }
180
- }
61
+ </View>
62
+ )}
63
+ </View>
64
+ </ActionSheetNative>
65
+ );
66
+ };
181
67
 
182
68
  ActionSheet.propTypes = {
183
69
  style: PropTypes.object.isRequired,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoutem/ui",
3
- "version": "7.1.0-beta.4",
3
+ "version": "7.1.0-beta.6",
4
4
  "description": "Styleable set of components for React Native applications",
5
5
  "scripts": {
6
6
  "lint": "eslint .",
@@ -41,12 +41,14 @@
41
41
  "react-native-vimeo-iframe": "^1.2.1",
42
42
  "react-native-webview": "11.23.0",
43
43
  "react-native-youtube-iframe": "2.2.2",
44
+ "react-native-actions-sheet": "0.9.3",
44
45
  "stream": "0.0.2",
45
46
  "tinycolor2": "1.4.1"
46
47
  },
47
48
  "peerDependencies": {
48
49
  "react": ">=16.9.0",
49
- "react-native": ">=0.61.5"
50
+ "react-native": ">=0.61.5",
51
+ "react-native-gesture-handler": "*"
50
52
  },
51
53
  "devDependencies": {
52
54
  "@babel/core": "7.16.7",
package/theme.js CHANGED
@@ -2714,13 +2714,7 @@ export default () => {
2714
2714
 
2715
2715
  'shoutem.ui.ActionSheet': {
2716
2716
  container: {
2717
- position: 'absolute',
2718
- top: 0,
2719
- bottom: 0,
2720
- left: 0,
2721
- right: 0,
2722
- flexDirection: 'column',
2723
- justifyContent: 'flex-end',
2717
+ backgroundColor: 'transparent',
2724
2718
  },
2725
2719
  contentContainer: {
2726
2720
  marginHorizontal: 8,
@@ -2744,10 +2738,11 @@ export default () => {
2744
2738
  text: {
2745
2739
  fontSize: 15,
2746
2740
  letterSpacing: 0.38,
2747
- color: '#000000',
2741
+ color: resolveVariable('primaryButtonText.color'),
2748
2742
  lineHeight: 24,
2749
2743
  },
2750
2744
  cancelText: {
2745
+ color: resolveVariable('errorText.color'),
2751
2746
  textAlign: 'center',
2752
2747
  fontWeight: resolveFontWeight('700'),
2753
2748
  },
@@ -17,7 +17,7 @@
17
17
  }
18
18
 
19
19
  .alert-actions {
20
- border-top: 1px solid #ABABAB;
20
+ border-top: 1px solid #DEDEDE;
21
21
  margin: 20px 0px 0px 0px;
22
22
  }
23
23
 
@@ -56,10 +56,14 @@
56
56
  width: 50%;
57
57
  }
58
58
 
59
- .third-width {
60
- width: 33%;
59
+ .button-height {
60
+ height: 50px;
61
61
  }
62
62
 
63
63
  .border-right {
64
- border-right: 1px solid #ABABAB;
64
+ border-right: 1px solid #DEDEDE;
65
+ }
66
+
67
+ .border-bottom {
68
+ border-bottom: 1px solid #DEDEDE;
65
69
  }