Skip to content

Commit ed8e0df

Browse files
authored
Merge pull request #723 from shoutem/release/5.2.0
Release/5.2.0
2 parents bc9a8c7 + f9dbe09 commit ed8e0df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1106
-718
lines changed

components/ActionSheet/ActionSheet.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ class ActionSheet extends PureComponent {
3333
return null;
3434
}
3535

36-
static propTypes = {
37-
style: PropTypes.any,
38-
confirmOptions: PropTypes.arrayOf(optionPropType),
39-
cancelOptions: PropTypes.arrayOf(optionPropType),
40-
active: PropTypes.bool,
41-
onDismiss: PropTypes.func,
42-
};
43-
4436
constructor(props) {
4537
super(props);
4638

@@ -187,4 +179,19 @@ class ActionSheet extends PureComponent {
187179
}
188180
}
189181

182+
ActionSheet.propTypes = {
183+
style: PropTypes.object.isRequired,
184+
active: PropTypes.bool,
185+
cancelOptions: PropTypes.arrayOf(optionPropType),
186+
confirmOptions: PropTypes.arrayOf(optionPropType),
187+
onDismiss: PropTypes.func,
188+
};
189+
190+
ActionSheet.defaultProps = {
191+
active: false,
192+
cancelOptions: undefined,
193+
confirmOptions: undefined,
194+
onDismiss: undefined,
195+
};
196+
190197
export default connectStyle('shoutem.ui.ActionSheet')(ActionSheet);

components/ActionSheet/ActionSheetOption.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ function ActionSheetOption({ style, option, cancelOption }) {
2626
}
2727

2828
ActionSheetOption.propTypes = {
29-
style: PropTypes.any,
30-
option: optionPropType,
29+
style: PropTypes.object.isRequired,
3130
cancelOption: PropTypes.bool,
31+
option: optionPropType,
32+
};
33+
34+
ActionSheetOption.defaultProps = {
35+
option: undefined,
36+
cancelOption: false,
3237
};
3338

3439
export default connectStyle('shoutem.ui.ActionSheetOption')(ActionSheetOption);

components/Button.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@ import { connectStyle } from '@shoutem/theme';
55

66
class Button extends PureComponent {
77
render() {
8-
// The underlayColor is not a valid RN style
9-
// property, so we have to unset it here.
10-
const style = {
11-
...this.props.style,
12-
};
13-
delete style.underlayColor;
8+
const { style, ...otherProps } = this.props;
9+
const { underlayColor, ...otherStyle } = style;
1410

1511
return (
1612
<TouchableOpacity
17-
{...this.props}
18-
style={style}
19-
underlayColor={this.props.style.underlayColor}
13+
{...otherProps}
14+
style={otherStyle}
15+
underlayColor={underlayColor}
2016
/>
2117
);
2218
}

components/CategoryPicker/Category.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { useMemo } from 'react';
2+
import PropTypes from 'prop-types';
3+
import { connectStyle } from '@shoutem/theme';
4+
import { Text } from '../Text';
5+
import { TouchableOpacity } from '../TouchableOpacity';
6+
import { categoryShape } from './shapes';
7+
8+
function Category({ category, style, isSelected, onPress }) {
9+
const textStyle = useMemo(
10+
() => [style.category, !isSelected && style.selectedCategory],
11+
12+
[isSelected, style.category, style.selectedCategory],
13+
);
14+
15+
function handlePress() {
16+
if (isSelected) {
17+
return;
18+
}
19+
20+
if (onPress) {
21+
onPress(category);
22+
}
23+
}
24+
25+
return (
26+
<TouchableOpacity onPress={handlePress} style={style.container}>
27+
<Text style={textStyle}>{category.name}</Text>
28+
</TouchableOpacity>
29+
);
30+
}
31+
32+
Category.propTypes = {
33+
category: categoryShape.isRequired,
34+
isSelected: PropTypes.bool,
35+
style: PropTypes.object,
36+
onPress: PropTypes.func,
37+
};
38+
39+
Category.defaultProps = {
40+
style: {},
41+
isSelected: false,
42+
onPress: undefined,
43+
};
44+
45+
export default React.memo(connectStyle('shoutem.ui.Category')(Category));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React, { useCallback } from 'react';
2+
import { FlatList } from 'react-native';
3+
import _ from 'lodash';
4+
import PropTypes from 'prop-types';
5+
import { connectStyle } from '@shoutem/theme';
6+
import { View } from '../View';
7+
import Category from './Category';
8+
import { categoryShape } from './shapes';
9+
10+
export function CategoryPicker({
11+
categories,
12+
onCategorySelected,
13+
style,
14+
selectedCategory,
15+
}) {
16+
const renderItem = useCallback(
17+
({ item: category }) => (
18+
<Category
19+
category={category}
20+
key={category.id}
21+
onPress={onCategorySelected}
22+
isSelected={selectedCategory.id === category.id}
23+
/>
24+
),
25+
[selectedCategory.id, onCategorySelected],
26+
);
27+
28+
if (_.size(categories) < 2) {
29+
return null;
30+
}
31+
32+
return (
33+
<View style={style.container}>
34+
<FlatList
35+
horizontal
36+
scrollToOverflowEnabled
37+
contentContainerStyle={style.listContainer}
38+
showsHorizontalScrollIndicator={false}
39+
data={categories}
40+
renderItem={renderItem}
41+
/>
42+
</View>
43+
);
44+
}
45+
46+
CategoryPicker.propTypes = {
47+
categories: PropTypes.arrayOf(categoryShape),
48+
selectedCategory: categoryShape,
49+
style: PropTypes.object,
50+
onCategorySelected: PropTypes.func,
51+
};
52+
53+
CategoryPicker.defaultProps = {
54+
categories: [],
55+
style: {},
56+
selectedCategory: undefined,
57+
onCategorySelected: undefined,
58+
};
59+
60+
export default React.memo(
61+
connectStyle('shoutem.ui.CategoryPicker')(CategoryPicker),
62+
);

components/CategoryPicker/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as CategoryPicker } from './CategoryPicker';

components/CategoryPicker/shapes.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import PropTypes from 'prop-types';
2+
3+
export const categoryShape = PropTypes.shape({
4+
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
5+
name: PropTypes.string.isRequired,
6+
description: PropTypes.string,
7+
});

components/DateTimePicker.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,24 @@ class DateTimePicker extends PureComponent {
198198
}
199199

200200
DateTimePicker.propTypes = {
201+
style: PropTypes.object.isRequired,
201202
cancelButtonText: PropTypes.string,
202203
confirmButtonText: PropTypes.string,
203204
is24Hour: PropTypes.bool,
204205
mode: PropTypes.oneOf(Object.values(DATEPICKER_MODES)),
205-
onValueChanged: PropTypes.func,
206206
textValue: PropTypes.string,
207207
value: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
208+
onValueChanged: PropTypes.func,
208209
};
209210

210211
DateTimePicker.defaultProps = {
211212
cancelButtonText: 'Cancel',
212213
confirmButtonText: 'Confirm',
213214
is24Hour: false,
214215
mode: 'datetime',
216+
textValue: undefined,
215217
value: new Date(),
218+
onValueChanged: undefined,
216219
};
217220

218221
const StyledDateTimePicker = connectStyle('shoutem.ui.DateTimePicker')(

components/DropDownMenu/DropDownMenu.js

+20-23
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,8 @@ import { View } from '../View';
1010
import { DropDownModal } from './DropDownModal';
1111

1212
const modalSpecificProps = ['visible', 'onClose'];
13-
const dropDownMenuPropTypes = {
14-
..._.omit(DropDownModal.propTypes, modalSpecificProps),
15-
};
1613

1714
class DropDownMenu extends PureComponent {
18-
/**
19-
* @see DropDownModal.propTypes
20-
*/
21-
static propTypes = {
22-
/**
23-
* Icon displayed on dropdown menu button
24-
*/
25-
iconName: PropTypes.string,
26-
/**
27-
* Whether the text should be displayed next to dropdown icon or not
28-
*/
29-
showSelectedOption: PropTypes.bool,
30-
...dropDownMenuPropTypes,
31-
};
32-
33-
static defaultProps = {
34-
iconName: 'drop-down',
35-
showSelectedOption: true,
36-
};
37-
3815
constructor(props) {
3916
super(props);
4017

@@ -105,6 +82,26 @@ class DropDownMenu extends PureComponent {
10582
}
10683
}
10784

85+
/**
86+
* @see DropDownModal.propTypes
87+
*/
88+
DropDownMenu.propTypes = {
89+
/**
90+
* Icon displayed on dropdown menu button
91+
*/
92+
iconName: PropTypes.string,
93+
/**
94+
* Whether the text should be displayed next to dropdown icon or not
95+
*/
96+
showSelectedOption: PropTypes.bool,
97+
..._.omit(DropDownModal.propTypes, modalSpecificProps),
98+
};
99+
100+
DropDownMenu.defaultProps = {
101+
iconName: 'drop-down',
102+
showSelectedOption: true,
103+
};
104+
108105
const StyledDropDownMenu = connectStyle('shoutem.ui.DropDownMenu')(
109106
DropDownMenu,
110107
);

0 commit comments

Comments
 (0)