Skip to content

Commit 6350059

Browse files
committed
StackAggregator - several fixes - see #3210
1 parent 8f25560 commit 6350059

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

demo/src/screens/componentScreens/StackAggregatorScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default class StackAggregatorScreen extends Component {
6868
containerStyle={{marginTop: 12}}
6969
onItemPress={this.onItemPress}
7070
collapsed={false}
71-
contentContainerStyle={{backgroundColor: Colors.red70}}
71+
backgroundColor={Colors.red70}
7272
// itemBorderRadius={10}
7373
// buttonProps={{color: Colors.green30, labelStyle: {...Typography.text80, fontWeight: '500'}}}
7474
>

src/components/stackAggregator/index.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const StackAggregator = (props: StackAggregatorProps) => {
7070
collapsed = true,
7171
disablePresses = false,
7272
onItemPress,
73+
backgroundColor,
7374
contentContainerStyle,
7475
itemBorderRadius = 0,
7576
onCollapseWillChange,
@@ -83,11 +84,11 @@ const StackAggregator = (props: StackAggregatorProps) => {
8384
setIsCollapsed(collapsed);
8485
}, [collapsed]);
8586

86-
useDidUpdate(() => {
87+
useDidUpdate(async () => {
8788
onCollapseWillChange?.(isCollapsed);
88-
animate();
89+
await animate();
8990
onCollapseChanged?.(isCollapsed);
90-
}, [isCollapsed, onCollapseWillChange, onCollapseChanged]);
91+
}, [isCollapsed, itemsCount]);
9192

9293
/** Animations */
9394

@@ -100,10 +101,11 @@ const StackAggregator = (props: StackAggregatorProps) => {
100101

101102
const getItemScale = useCallback((index: number) => {
102103
if (isCollapsed) {
103-
if (index === itemsCount - 2) {
104+
if (index === 1) {
104105
return 0.95;
105106
}
106-
if (index === itemsCount - 1) {
107+
108+
if (index === 2) {
107109
return 0.9;
108110
}
109111
}
@@ -185,10 +187,11 @@ const StackAggregator = (props: StackAggregatorProps) => {
185187
const getTop = (index: number) => {
186188
let start = 0;
187189

188-
if (index === itemsCount - 2) {
190+
if (index === 1) {
189191
start += PEEP;
190192
}
191-
if (index === itemsCount - 1) {
193+
194+
if (index === 2) {
192195
start += PEEP * 2;
193196
}
194197

@@ -218,6 +221,10 @@ const StackAggregator = (props: StackAggregatorProps) => {
218221
];
219222
}, [firstItemHeight, itemsCount]);
220223

224+
const cardStyle = useMemo(() => {
225+
return backgroundColor ? [styles.card, {backgroundColor}] : styles.card;
226+
}, [backgroundColor]);
227+
221228
/** Events */
222229

223230
const _onItemPress = (index: number) => {
@@ -241,7 +248,7 @@ const StackAggregator = (props: StackAggregatorProps) => {
241248
<Animated.View
242249
onLayout={index === 0 ? onLayout : undefined}
243250
style={[
244-
Constants.isIOS && styles.containerShadow,
251+
Constants.isIOS && (index === 0 || index === 1 || index === 2 || !isCollapsed) && styles.containerShadow,
245252
contentContainerStyle,
246253
//@ts-expect-error 'position' doesn't match AnimatedInterpolation type
247254
getItemStyle(index),
@@ -256,7 +263,7 @@ const StackAggregator = (props: StackAggregatorProps) => {
256263
]}
257264
collapsable={false}
258265
>
259-
<Card style={styles.card} onPress={() => _onItemPress(index)} borderRadius={itemBorderRadius} elevation={5}>
266+
<Card style={cardStyle} onPress={() => _onItemPress(index)} borderRadius={itemBorderRadius} elevation={5}>
260267
<Animated.View style={index !== 0 ? {opacity: animatedContentOpacity} : undefined} collapsable={false}>
261268
{item}
262269
</Animated.View>
@@ -319,8 +326,7 @@ const styles = StyleSheet.create({
319326
},
320327
card: {
321328
overflow: 'hidden',
322-
flexShrink: 1,
323-
backgroundColor: 'transparent'
329+
flexShrink: 1
324330
},
325331
button: {
326332
zIndex: 100

0 commit comments

Comments
 (0)