From ede065c8b06ff7b0fb5fdb659cb85ca01f76bd3c Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Wed, 3 Mar 2021 01:07:45 -0800 Subject: [PATCH] SectionList example add updateProps to example Summary: # Changelog [General][Added] - Expand example in RNTester for separators on VirtualizedSectionList to showcase updating props on separator ("has not been pressed" -> "has been pressed") Reviewed By: nadiia, kacieb Differential Revision: D26713429 fbshipit-source-id: 21034fab5a80d46c46462c41b0989cc9e4c45d03 --- .../SectionList/SectionListExamples.js | 71 +++++++++++-------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/packages/rn-tester/js/examples/SectionList/SectionListExamples.js b/packages/rn-tester/js/examples/SectionList/SectionListExamples.js index 6eb9eb4c2dc..df68a5209f4 100644 --- a/packages/rn-tester/js/examples/SectionList/SectionListExamples.js +++ b/packages/rn-tester/js/examples/SectionList/SectionListExamples.js @@ -46,8 +46,16 @@ const VIEWABILITY_CONFIG = { const Item = ({item, section, separators}) => { return ( { + separators.highlight(); + }} + onPress={() => { + separators.updateProps('trailing', {hasBeenHighlighted: true}); + separators.updateProps('leading', {hasBeenHighlighted: true}); + }} + onPressOut={() => { + separators.unhighlight(); + }} style={({pressed}) => [ styles.item, { @@ -60,7 +68,18 @@ const Item = ({item, section, separators}) => { ); }; -const Separator = (defaultColor, highlightColor, text) => ({highlighted}) => { +const Separator = (defaultColor, highlightColor, isSectionSeparator) => ({ + leadingItem, + trailingItem, + highlighted, + hasBeenHighlighted, +}) => { + const text = `${ + isSectionSeparator ? 'Section ' : '' + }separator for leading ${leadingItem} and trailing ${trailingItem} has ${ + !hasBeenHighlighted ? 'not ' : '' + }been pressed`; + return ( >(); - const onTest = null; - return ( - + ); } @@ -232,7 +240,6 @@ export function SectionList_onViewableItemsChanged(): React.Node { return ( ); @@ -242,7 +249,7 @@ type Props = { exampleProps: $Shape>, onTest?: ?() => void, testLabel?: ?string, - testOutput: ?string, + testOutput?: ?string, }; const SectionListExampleWithForwardedRef = React.forwardRef( @@ -252,18 +259,20 @@ const SectionListExampleWithForwardedRef = React.forwardRef( ): React.Node { return ( - - - {props.testOutput} - - {props.onTest != null ? ( -