Created
March 19, 2024 04:21
-
-
Save john24alex/301cfe80a915a999a0080b662a34b12c to your computer and use it in GitHub Desktop.
Scroll View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="root"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of scroll view adapted to be shown on web, with sanme expected behavior | |
class App extends React.Component { | |
render() { | |
return ( | |
<div style={{ borderWidth: 2, borderColor: 'black', ...styles.root }}> | |
<Header headerText="ScrollView Example" /> | |
<div style={styles.scrollView}> | |
{Array.from({ length: 10 }).map((_, index) => ( | |
<div key={index} style={styles.item}> | |
<p>Item {index + 1}</p> | |
</div> | |
))} | |
</div> | |
</div> | |
); | |
} | |
} | |
const Header = (props) => ( | |
<div style={{ ...styles.header, borderWidth: 2, borderColor: 'red', borderRadius: 5 }}> | |
<p style={{ color: '#fff' }}>{props.headerText}</p> | |
</div> | |
); | |
// General styles addind flex to scroll view | |
const styles = { | |
root: { | |
width: '360px', | |
height: '640px', | |
backgroundColor: 'blue', | |
display: 'flex', | |
flexDirection: 'column', | |
padding: '8px', | |
}, | |
header: { | |
backgroundColor: '#545353', | |
alignItems: 'center', | |
justifyContent: 'center', | |
height: '44px', | |
color: '#fff', | |
display: 'flex', | |
flexDirection: 'column', | |
padding: '8px', | |
}, | |
scrollView: { | |
flex: 1, | |
width: '100%', | |
overflowY: 'scroll', | |
}, | |
contentContainer: { | |
alignItems: 'center', | |
paddingBottom: 0, | |
}, | |
item: { | |
backgroundColor: 'white', | |
padding: '20px', | |
marginVertical: '10px', | |
width: '90%', | |
display: 'flex', | |
alignItems: 'center', | |
justifyContent: 'center', | |
borderRadius: '5px', | |
marginBottom: '10px', | |
}, | |
}; | |
// Replace ReactDOM.createRoot to work in CodePen | |
const root = ReactDOM.createRoot(document.getElementById('root')); | |
// render mode to validate that works in codepen | |
root.render(<App />); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-native-web/0.19.10/index.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body, html { | |
margin: 0; | |
padding: 0; | |
font-family: Arial, sans-serif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment