|
| 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; |
0 commit comments