Skip to content

Commit dfb4f4a

Browse files
dy93facebook-github-bot
authored andcommitted
issue #18943 - SectionSeparatorComponent and ItemSeparatorComponent s… (#26933)
Summary: SectionSeparatorComponent and ItemSeparatorComponent should displays in the correct place with an inverted list This PR fix issue #18943 Currently, when using SectionSeparatorComponent and ItemSeparatorComponent with an inverted SectionList, the separators will display at the wrong place. Please see issue #18943 for more information. ## Changelog [General] [Fixed] - Fix separators displays in wrong places with the inverted list Pull Request resolved: #26933 Test Plan: before this fix, the following code will result in following screenshots: ``` import React from 'react'; import { StyleSheet, Text, SectionList, SafeAreaView } from 'react-native'; export default function App() { return ( <SafeAreaView style={styles.container}> <SectionList style={{ width: '100%' }} sections={[ { data: ['item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6', 'item 7'] } ]} renderItem={({ item }) => <Text style={{ fontSize: 18, backgroundColor: 'greenyellow', width: '100%' }}>{item}</Text>} inverted SectionSeparatorComponent={() => <Text style={{ fontSize: 28, backgroundColor: 'fuchsia', width: '100%' }}>section separator</Text>} ItemSeparatorComponent={() => <Text style={{ fontSize: 12, backgroundColor: 'gold', width: '100%' }}>item separator</Text>} renderSectionHeader={()=><Text style={{ fontSize: 38, backgroundColor: 'lightpink', width: '100%' }}>section header</Text>} renderSectionFooter={()=><Text style={{ fontSize: 38, backgroundColor: 'lightpink', width: '100%' }}>section footer</Text>} /> </SafeAreaView> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, }); ``` <img width="413" alt="螢幕快照 2019-10-21 下午12 23 36" src="https://user-images.githubusercontent.com/1477985/67176763-030df580-f3fe-11e9-938f-38939339bf5c.png"> after this fix, the separators will display in the right place <img width="414" alt="螢幕快照 2019-10-21 下午12 23 51" src="https://user-images.githubusercontent.com/1477985/67176795-2042c400-f3fe-11e9-96f3-a8ea1cfb28a2.png"> Differential Revision: D18174225 Pulled By: cpojer fbshipit-source-id: 30901e68f38326c69715514a09a7a5130a2332a0
1 parent d7c222a commit dfb4f4a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Libraries/Lists/VirtualizedSectionList.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ class VirtualizedSectionList<
374374
section={info.section}
375375
trailingItem={info.trailingItem}
376376
trailingSection={info.trailingSection}
377+
inverted={!!this.props.inverted}
377378
/>
378379
);
379380
}
@@ -435,6 +436,7 @@ type ItemWithSeparatorProps = $ReadOnly<{|
435436
onUpdateSeparator: (cellKey: string, newProps: Object) => void,
436437
prevCellKey?: ?string,
437438
renderItem: Function,
439+
inverted: boolean,
438440
|}>;
439441

440442
type ItemWithSeparatorState = {
@@ -534,6 +536,7 @@ class ItemWithSeparator extends React.Component<
534536
item,
535537
index,
536538
section,
539+
inverted,
537540
} = this.props;
538541
const element = this.props.renderItem({
539542
item,
@@ -552,9 +555,9 @@ class ItemWithSeparator extends React.Component<
552555
* error found when Flow v0.89 was deployed. To see the error, delete
553556
* this comment and run Flow. */
554557
<View>
555-
{leadingSeparator}
558+
{!inverted ? leadingSeparator : separator}
556559
{element}
557-
{separator}
560+
{!inverted ? separator : leadingSeparator}
558561
</View>
559562
) : (
560563
element

Libraries/Lists/__tests__/__snapshots__/VirtualizedSectionList-test.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -751,10 +751,10 @@ exports[`VirtualizedSectionList renders all the bells and whistles 1`] = `
751751
}
752752
>
753753
<View>
754+
<separator />
754755
<item
755756
value="0"
756757
/>
757-
<separator />
758758
</View>
759759
</View>
760760
<View
@@ -774,10 +774,10 @@ exports[`VirtualizedSectionList renders all the bells and whistles 1`] = `
774774
}
775775
>
776776
<View>
777+
<separator />
777778
<item
778779
value="1"
779780
/>
780-
<separator />
781781
</View>
782782
</View>
783783
<View
@@ -797,10 +797,10 @@ exports[`VirtualizedSectionList renders all the bells and whistles 1`] = `
797797
}
798798
>
799799
<View>
800+
<separator />
800801
<item
801802
value="2"
802803
/>
803-
<separator />
804804
</View>
805805
</View>
806806
<View
@@ -820,10 +820,10 @@ exports[`VirtualizedSectionList renders all the bells and whistles 1`] = `
820820
}
821821
>
822822
<View>
823+
<separator />
823824
<item
824825
value="3"
825826
/>
826-
<separator />
827827
</View>
828828
</View>
829829
<View

0 commit comments

Comments
 (0)