Skip to content

Commit 77c9113

Browse files
StackAggregator - fix children update (#2103)
* StackAggregator - migrate to functional component * fix styling issue * fix style for contentContainerStyle * Revert "fix style for contentContainerStyle" This reverts commit 283a0d8. * change default * apply contentContainerStyle of collapsed items * fix style updates when collapsing changes * remove style duplication * Update collapsed state * fix for layout animation doesn't effect on first interaction * Fix animation timing Co-authored-by: Ethan Sharabi <[email protected]>
1 parent 9522661 commit 77c9113

File tree

2 files changed

+211
-187
lines changed

2 files changed

+211
-187
lines changed

demo/src/screens/componentScreens/StackAggregatorScreen.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import {ScrollView} from 'react-native';
44
import {Colors, View, Text, Button, StackAggregator} from 'react-native-ui-lib';
55

66

7-
const contents = [
7+
const TEXTS = [
88
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
99
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
1010
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
1111
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum is simply dummy text of the printing and typesetting industry.'
1212
];
1313

1414
export default class StackAggregatorScreen extends Component {
15-
15+
state = {
16+
contents: TEXTS,
17+
collapsed: true
18+
};
19+
1620
onItemPress = (index: number) => {
1721
console.warn('item pressed: ', index);
1822
}
@@ -21,24 +25,41 @@ export default class StackAggregatorScreen extends Component {
2125
console.warn('item\'s button pressed: ', index);
2226
}
2327

28+
refreshItems = () => {
29+
const newItems = _.clone(this.state.contents);
30+
newItems.push('New Item');
31+
this.setState({contents: newItems});
32+
}
33+
34+
toggleCollapsed = () => {
35+
this.setState({collapsed: !this.state.collapsed});
36+
}
37+
2438
renderItem = (_: string, index: number) => {
2539
return (
2640
<View key={index} center padding-12>
2741
<Button label={`${index}`} marginB-10 size={Button.sizes.small} onPress={() => this.onPress(index)}/>
28-
<Text>{contents[index]}</Text>
42+
<Text>{this.state.contents[index]}</Text>
2943
</View>
3044
);
3145
}
3246

3347
render() {
48+
const {collapsed} = this.state;
49+
3450
return (
3551
<ScrollView keyboardShouldPersistTaps={'handled'} showsVerticalScrollIndicator={false}>
52+
<View row spread margin-5>
53+
<Button link label={collapsed ? 'Open Stack' : 'Close Stack'} onPress={this.toggleCollapsed}/>
54+
<Button link label="Update content" onPress={this.refreshItems}/>
55+
</View>
3656
<Text center grey40 text90 marginT-20>Thu, 10 Dec, 11:29</Text>
3757
<StackAggregator
3858
containerStyle={{marginTop: 12}}
3959
onItemPress={this.onItemPress}
60+
collapsed={collapsed}
4061
>
41-
{_.map(contents, (item, index) => {
62+
{_.map(this.state.contents, (item, index) => {
4263
return this.renderItem(item, index);
4364
})}
4465
</StackAggregator>
@@ -52,7 +73,7 @@ export default class StackAggregatorScreen extends Component {
5273
// itemBorderRadius={10}
5374
// buttonProps={{color: Colors.green30, labelStyle: {...Typography.text80, fontWeight: '500'}}}
5475
>
55-
{_.map(contents, (item, index) => {
76+
{_.map(this.state.contents, (item, index) => {
5677
return this.renderItem(item, index);
5778
})}
5879
</StackAggregator>

0 commit comments

Comments
 (0)