Skip to content

Commit 071845d

Browse files
committed
Create new example screen for View (modifiers)
1 parent 949d936 commit 071845d

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

demo/src/screens/ExampleScreenPresenter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function renderRadioGroup(title, key, options, {isRow} = {}) {
3030
key={key}
3131
marginB-s2
3232
marginR-s2={isRow}
33-
label={value}
34-
value={options[key]}
33+
label={key}
34+
value={value}
3535
/>
3636
);
3737
})}

demo/src/screens/MenuStructure.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const navigationData = {
4444
{title: 'TabBar', tags: 'tab bar', screen: 'unicorn.components.TabBarScreen'},
4545
{title: 'Text', tags: 'text', screen: 'unicorn.components.TextScreen'},
4646
{title: 'Toast', tags: 'toast top bottom snackbar', screen: 'unicorn.components.ToastsScreen'},
47+
{title: 'View', tags: 'view modifiers', screen: 'unicorn.components.ViewScreen'},
4748
{title: 'Wheel Picker Dialog', tags: 'wheel picker dialog', screen: 'unicorn.components.WheelPickerDialogScreen'},
4849
{title: 'Wizard', tags: 'wizard', screen: 'unicorn.components.WizardScreen'}
4950
]
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React, {Component} from 'react';
2+
import {ScrollView} from 'react-native';
3+
import {View, Text} from 'react-native-ui-lib';
4+
import _ from 'lodash';
5+
import {renderBooleanOption, renderRadioGroup, renderSliderOption, renderColorOption} from '../ExampleScreenPresenter';
6+
7+
const ALIGNMENTS = {
8+
top: 'top',
9+
bottom: 'bottom',
10+
left: 'left',
11+
right: 'right',
12+
center: 'center',
13+
centerv: 'centerV',
14+
centerh: 'centerH',
15+
spread: 'spread',
16+
none: null
17+
};
18+
19+
const POSITIONS = {
20+
absolute: 'abs',
21+
'absolute Fill': 'absF',
22+
'absolute Left': 'absL',
23+
'absolute Right': 'absR',
24+
'absolute Vertical': 'absV',
25+
'absolute Horizontal': 'absH',
26+
none: null
27+
};
28+
29+
class ViewScreen extends Component {
30+
state = {
31+
useRow: false,
32+
shouldFlex: false,
33+
borderRadius: 20,
34+
padding: 0,
35+
margin: 0,
36+
alignment: null,
37+
position: null
38+
};
39+
40+
render() {
41+
const {useRow, shouldFlex, borderRadius, padding, margin, alignment, position} = this.state;
42+
const childOptions = {
43+
flex: shouldFlex,
44+
width: shouldFlex || _.includes(['absF', 'absH'], position) ? undefined : 50,
45+
height: shouldFlex || _.includes(['absF', 'absV'], position) ? undefined : 50,
46+
[position]: true
47+
};
48+
const parentOptions = {
49+
row: useRow,
50+
[`br${borderRadius}`]: true,
51+
[`padding-${padding}`]: true,
52+
[`margin-${margin}`]: true,
53+
[alignment]: true
54+
};
55+
56+
return (
57+
<View flex>
58+
<View padding-s5>
59+
<Text text40>View</Text>
60+
61+
<View key={JSON.stringify(parentOptions)} bg-purple40 height={200} {...parentOptions}>
62+
<View bg-blue40 {...childOptions}/>
63+
<View width={40} height={40} bg-yellow20/>
64+
</View>
65+
</View>
66+
<ScrollView>
67+
<View padding-s5>
68+
<View height={2} bg-grey60 marginB-20/>
69+
{renderBooleanOption.call(this, 'Row (parent)', 'useRow')}
70+
{renderBooleanOption.call(this, 'Flex (child)', 'shouldFlex')}
71+
{renderSliderOption.call(this, 'BorderRadius(brXX)', 'borderRadius', {step: 10, min: 0, max: 60})}
72+
{renderSliderOption.call(this, 'Padding(padding-XX)', 'padding', {step: 4, min: 0, max: 40})}
73+
{renderSliderOption.call(this, 'Margin(margin-XX)', 'margin', {step: 4, min: 0, max: 40})}
74+
{renderRadioGroup.call(this, 'Alignment (parent)', 'alignment', ALIGNMENTS)}
75+
{renderRadioGroup.call(this, 'Position (child)', 'position', POSITIONS)}
76+
</View>
77+
</ScrollView>
78+
</View>
79+
);
80+
}
81+
}
82+
83+
export default ViewScreen;

demo/src/screens/componentScreens/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ Navigation.registerComponent('unicorn.components.ColorPickerScreen', () => requi
3939
Navigation.registerComponent('unicorn.components.ColorSwatchScreen', () => require('./ColorSwatchScreen').default);
4040
Navigation.registerComponent('unicorn.components.StackAggregatorScreen', () => require('./StackAggregatorScreen').default);
4141
Navigation.registerComponent('unicorn.components.DateTimePickerScreen', () => require('./DateTimePickerScreen').default);
42+
Navigation.registerComponent('unicorn.components.ViewScreen', () => require('./ViewScreen').default);
4243
Navigation.registerComponent('unicorn.components.WizardScreen', () => require('./WizardScreen').default);

0 commit comments

Comments
 (0)