Skip to content

Commit

Permalink
feat(ScrollPanel): add ScrollPanel component
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Bien committed Dec 12, 2020
1 parent ae358b7 commit 108622d
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
44 changes: 44 additions & 0 deletions example/src/examples/ScrollPanelExample.tsx
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;
2 changes: 2 additions & 0 deletions example/src/examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import MenuExample from './MenuExample';
import PanelExample from './PanelExample';
import ProgressExample from './ProgressExample';
import RadioExample from './RadioExample';
import ScrollPanelExample from './ScrollPanelExample';
import SelectBoxExample from './SelectBoxExample';
import SelectExample from './SelectExample';
import TabsExample from './TabsExample';
Expand Down Expand Up @@ -58,6 +59,7 @@ export default [
title: 'Divider',
},
{ name: 'PanelExample', component: PanelExample, title: 'Panel' },
{ name: 'ScrollPanelExample', component: ScrollPanelExample, title: 'ScrollPanel' },
{ name: 'WindowExample', component: WindowExample, title: 'Window' },
],
},
Expand Down
66 changes: 66 additions & 0 deletions src/ScrollPanel/ScrollPanel.tsx
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;
1 change: 1 addition & 0 deletions src/ScrollPanel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ScrollPanel';
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export { default as Tabs } from './Tabs';
export { default as ScrollView } from './ScrollView';
export { default as Hourglass } from './Hourglass';
export { default as List } from './List';
export { default as ScrollPanel } from './ScrollPanel';

export * from './common/theming';

0 comments on commit 108622d

Please sign in to comment.