@shoutem/ui 8.1.3-rc.5 → 8.2.1-rc.0
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<?xml version="1.0" ?><svg height="48" viewBox="0 0 48 48" width="48" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h48v48H0zm36.62 12L31.1 22z" fill="none"/><path d="M22 18h4v-6h6V8h-6V2h-4v6h-6v4h6v6zm-8 18c-2.21 0-3.98 1.79-3.98 4s1.77 4 3.98 4 4-1.79 4-4-1.79-4-4-4zm20 0c-2.21 0-3.98 1.79-3.98 4s1.77 4 3.98 4 4-1.79 4-4-1.79-4-4-4zm-19.65-6.5c0-.09.02-.17.06-.24l1.8-3.26h14.9c1.5 0 2.81-.83 3.5-2.06l7.72-14.02L38.83 8h-.01l-2.21 4-5.51 10H17.07l-.26-.54L12.32 12l-1.9-4-1.89-4H2v4h4l7.2 15.17-2.71 4.9c-.31.58-.49 1.23-.49 1.93 0 2.21 1.79 4 4 4h24v-4H14.85c-.28 0-.5-.22-.5-.5z"/></svg>
|
|
@@ -5,6 +5,7 @@ import addFriend from './add-friend.svg';
|
|
|
5
5
|
import addToCart from './add-to-cart.svg';
|
|
6
6
|
import addToFavoritesOff from './add-to-favorites-off.svg';
|
|
7
7
|
import addToFavoritesOn from './add-to-favorites-on.svg';
|
|
8
|
+
import addToShoppingCart from './add-to-shopping-cart.svg';
|
|
8
9
|
import address from './address.svg';
|
|
9
10
|
import attachMedia from './attach-media.svg';
|
|
10
11
|
import back from './back.svg';
|
|
@@ -135,6 +136,7 @@ export const defaultConfig = [
|
|
|
135
136
|
{ name: 'add-event', icon: addEvent },
|
|
136
137
|
{ name: 'add-friend', icon: addFriend },
|
|
137
138
|
{ name: 'add-to-cart', icon: addToCart },
|
|
139
|
+
{ name: 'add-to-shopping-cart', icon: addToShoppingCart },
|
|
138
140
|
{ name: 'add-to-favorites-off', icon: addToFavoritesOff },
|
|
139
141
|
{ name: 'add-to-favorites-on', icon: addToFavoritesOn },
|
|
140
142
|
{ name: 'address', icon: address },
|
|
@@ -11,70 +11,76 @@ class TabMenu extends PureComponent {
|
|
|
11
11
|
constructor(props) {
|
|
12
12
|
super(props);
|
|
13
13
|
|
|
14
|
+
this.scroll = {};
|
|
15
|
+
|
|
14
16
|
autoBindReact(this);
|
|
15
17
|
|
|
16
18
|
this.state = {
|
|
17
19
|
itemWidths: {},
|
|
18
|
-
|
|
20
|
+
viewportHorizontal: [],
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
componentDidMount() {
|
|
25
|
+
this.scrollToSelectedItem();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
componentDidUpdate(prevProps) {
|
|
29
|
+
const { selectedOption } = this.props;
|
|
30
|
+
|
|
31
|
+
if (prevProps.selectedOption !== selectedOption) {
|
|
32
|
+
this.scrollToSelectedItem();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
scrollToSelectedItem() {
|
|
37
|
+
const { selectedOption, options } = this.props;
|
|
38
|
+
const { itemWidths, viewportHorizontal } = this.state;
|
|
39
|
+
|
|
40
|
+
if (!selectedOption || !options.length || !this.scroll) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const selectedIndex = options.findIndex(
|
|
45
|
+
option => option.id === selectedOption.id,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (selectedIndex === -1) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
25
51
|
|
|
26
52
|
let itemStart = 0;
|
|
27
53
|
|
|
28
54
|
_.forEach(itemWidths, (itemWidth, index) => {
|
|
29
|
-
if (index <
|
|
55
|
+
if (index < selectedIndex) {
|
|
30
56
|
itemStart += itemWidth;
|
|
31
57
|
}
|
|
32
58
|
});
|
|
33
59
|
|
|
34
|
-
const itemEnd = itemStart + itemWidths[
|
|
35
|
-
|
|
36
|
-
LayoutAnimation.easeInEaseOut();
|
|
37
|
-
onOptionSelected(option);
|
|
60
|
+
const itemEnd = itemStart + itemWidths[selectedIndex];
|
|
38
61
|
|
|
62
|
+
// Ensure item is in view
|
|
39
63
|
if (itemEnd > _.last(viewportHorizontal)) {
|
|
40
64
|
const extraScroll = itemEnd - _.last(viewportHorizontal);
|
|
41
|
-
|
|
42
|
-
this.scroll.scrollTo({
|
|
43
|
-
x: extraScroll + scrollOffset,
|
|
44
|
-
y: 0,
|
|
45
|
-
animated: true,
|
|
46
|
-
});
|
|
65
|
+
this.scroll.scrollTo({ x: extraScroll, y: 0, animated: true });
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
if (itemStart < _.head(viewportHorizontal)) {
|
|
50
|
-
const extraScroll = _.head(viewportHorizontal) - itemStart;
|
|
51
|
-
|
|
52
69
|
this.scroll.scrollTo({
|
|
53
|
-
x:
|
|
70
|
+
x: itemStart,
|
|
54
71
|
y: 0,
|
|
55
72
|
animated: true,
|
|
56
73
|
});
|
|
57
74
|
}
|
|
58
75
|
}
|
|
59
76
|
|
|
60
|
-
handleItemLayout(key, width) {
|
|
61
|
-
const { itemWidths } = this.state;
|
|
62
|
-
|
|
63
|
-
this.setState({
|
|
64
|
-
itemWidths: {
|
|
65
|
-
...itemWidths,
|
|
66
|
-
[key]: width,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
77
|
handleScroll({
|
|
72
78
|
nativeEvent: {
|
|
73
79
|
contentOffset: { x },
|
|
74
80
|
layoutMeasurement: { width },
|
|
75
81
|
},
|
|
76
82
|
}) {
|
|
77
|
-
this.setState({
|
|
83
|
+
this.setState({ viewportHorizontal: [x, width] });
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
handleScrollLayout({
|
|
@@ -85,6 +91,24 @@ class TabMenu extends PureComponent {
|
|
|
85
91
|
this.setState({ viewportHorizontal: [0, width] });
|
|
86
92
|
}
|
|
87
93
|
|
|
94
|
+
handleItemLayout(key, width) {
|
|
95
|
+
const { itemWidths } = this.state;
|
|
96
|
+
|
|
97
|
+
this.setState({
|
|
98
|
+
itemWidths: {
|
|
99
|
+
...itemWidths,
|
|
100
|
+
[key]: width,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
handleOptionSelected(option) {
|
|
106
|
+
const { onOptionSelected } = this.props;
|
|
107
|
+
|
|
108
|
+
LayoutAnimation.easeInEaseOut();
|
|
109
|
+
onOptionSelected(option);
|
|
110
|
+
}
|
|
111
|
+
|
|
88
112
|
renderOption(option, key) {
|
|
89
113
|
const { selectedOption } = this.props;
|
|
90
114
|
|
|
@@ -95,7 +119,7 @@ class TabMenu extends PureComponent {
|
|
|
95
119
|
key={key}
|
|
96
120
|
isSelected={isSelected}
|
|
97
121
|
item={option}
|
|
98
|
-
onItemPressed={option => this.handleOptionSelected(
|
|
122
|
+
onItemPressed={option => this.handleOptionSelected(option)}
|
|
99
123
|
onLayoutMeasured={width => this.handleItemLayout(key, width)}
|
|
100
124
|
/>
|
|
101
125
|
);
|
|
@@ -113,6 +137,7 @@ class TabMenu extends PureComponent {
|
|
|
113
137
|
ref={ref => {
|
|
114
138
|
this.scroll = ref;
|
|
115
139
|
}}
|
|
140
|
+
scrollEventThrottle={16}
|
|
116
141
|
showsHorizontalScrollIndicator={false}
|
|
117
142
|
style={style.list}
|
|
118
143
|
>
|
package/package.json
CHANGED