Skip to content

Commit

Permalink
Add an example showing the prop contentInset in SectionList
Browse files Browse the repository at this point in the history
Summary:
This prop is iOS only.

Changelog:
[iOS][Added] Add an example showing the prop contentInset in SectionList

Reviewed By: lunaleaps

Differential Revision: D26491787

fbshipit-source-id: 31398388081a22ccd17cc256aa174ffe7764e7a9
  • Loading branch information
kacieb authored and facebook-github-bot committed Feb 18, 2021
1 parent 16cf45a commit 28fb41a
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions packages/rn-tester/js/examples/SectionList/SectionListExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,50 @@ export function SectionList_inverted(): React.Node {
);
}

export function SectionList_contentInset(): React.Node {
const [initialContentInset, toggledContentInset] = [44, 88];

const [output, setOutput] = React.useState(
`contentInset top: ${initialContentInset.toString()}`,
);
const [exampleProps, setExampleProps] = React.useState({
automaticallyAdjustContentInsets: false,
contentInset: {top: initialContentInset},
contentOffset: {y: -initialContentInset, x: 0},
});

const onTest = () => {
const newContentInset =
exampleProps.contentInset.top === initialContentInset
? toggledContentInset
: initialContentInset;
setExampleProps({
automaticallyAdjustContentInsets: false,
contentInset: {top: newContentInset},
contentOffset: {y: -newContentInset, x: 0},
});
setOutput(`contentInset top: ${newContentInset.toString()}`);
};

return (
<>
<View
style={[
styles.titleContainer,
{height: exampleProps.contentInset.top},
]}>
<Text style={styles.titleText}>Menu</Text>
</View>
<SectionListExampleWithForwardedRef
exampleProps={exampleProps}
testOutput={output}
onTest={onTest}
testLabel={'Toggle header size'}
/>
</>
);
}

export function SectionList_stickySectionHeadersEnabled(): React.Node {
const [output, setOutput] = React.useState(
'stickySectionHeadersEnabled false',
Expand Down Expand Up @@ -196,6 +240,21 @@ const styles = StyleSheet.create({
title: {
fontSize: 24,
},
titleContainer: {
position: 'absolute',
top: 45,
left: 0,
right: 0,
justifyContent: 'flex-end',
alignItems: 'center',
backgroundColor: 'gray',
zIndex: 1,
},
titleText: {
fontSize: 24,
lineHeight: 44,
fontWeight: 'bold',
},
testContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
Expand Down

0 comments on commit 28fb41a

Please sign in to comment.