-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ScrollPanel): add ScrollPanel component
- Loading branch information
Artur Bien
committed
Dec 12, 2020
1 parent
ae358b7
commit 108622d
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import { View, Text, StyleSheet } from 'react-native'; | ||
import { ScrollPanel } from 'react95-native'; | ||
|
||
function getRandomColor() { | ||
var letters = '0123456789ABCDEF'; | ||
var color = '#'; | ||
for (var i = 0; i < 6; i++) { | ||
color += letters[Math.floor(Math.random() * 16)]; | ||
} | ||
return color; | ||
} | ||
|
||
const ScrollPanelExample = () => { | ||
|
||
const colors = new Array(16).fill(null).map(getRandomColor); | ||
|
||
return ( | ||
<View style={{ backgroundColor: 'teal', flex: 1 }}> | ||
<ScrollPanel> | ||
{colors.map((color, i) => ( | ||
<View key={i} style={[styles.item, { backgroundColor: color }]} /> | ||
))} | ||
</ScrollPanel> | ||
<ScrollPanel noBackground> | ||
{colors.map((color, i) => ( | ||
<View key={i} style={[styles.item, { backgroundColor: color }]} /> | ||
))} | ||
</ScrollPanel> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
item: { | ||
height: 60, | ||
width: 60, | ||
borderRadius: 20, | ||
backgroundColor: 'teal', | ||
marginHorizontal: 8, | ||
}, | ||
}); | ||
|
||
export default ScrollPanelExample; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react'; | ||
import { View, StyleSheet, ScrollView } from 'react-native'; | ||
import type { StyleProp, ViewStyle } from 'react-native'; | ||
import { ThemeContext } from '../common/theming/Theme'; | ||
|
||
import { Border } from '../common/styleElements'; | ||
import { Divider } from '..'; | ||
|
||
// TODO: where to pass custom styles? | ||
// TODO: add noBottomBorder and noTopBorder prop | ||
type Props = { | ||
style?: StyleProp<ViewStyle>; | ||
children?: React.ReactNode; | ||
noBackground?: boolean; | ||
}; | ||
|
||
const ScrollPanel = ({ style = {}, children, noBackground }: Props) => { | ||
const theme = React.useContext(ThemeContext); | ||
|
||
return ( | ||
<View | ||
style={[ | ||
{ | ||
backgroundColor: noBackground ? 'transparent' : theme.materialDark, | ||
}, | ||
]} | ||
> | ||
<ScrollView horizontal={true} showsHorizontalScrollIndicator={false}> | ||
<View style={[styles.borderWrapper]}> | ||
<Border variant='outside' /> | ||
<View | ||
style={[styles.inner, { backgroundColor: theme.material }, style]} | ||
> | ||
<Divider orientation='vertical' variant='raised' /> | ||
<Divider orientation='vertical' variant='raised' /> | ||
<View style={[styles.content]}>{children}</View> | ||
</View> | ||
</View> | ||
</ScrollView> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
inner: { | ||
padding: 16, | ||
// TODO: decide if left padding should be 8 or 16 | ||
paddingLeft: 16, | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
borderWrapper: { | ||
padding: 4, | ||
position: 'relative', | ||
minWidth: '100%' | ||
}, | ||
content: { | ||
marginLeft: 8, | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
}); | ||
|
||
export default ScrollPanel; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './ScrollPanel'; |
This file contains 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