项目作者: react-ui-kit

项目描述 :
expo-ui-kit - a components based React-Native UI Kit
高级语言: JavaScript
项目地址: git://github.com/react-ui-kit/expo-ui-kit.git
创建时间: 2019-03-24T14:21:18Z
项目社区:https://github.com/react-ui-kit/expo-ui-kit

开源协议:MIT License

下载


expo-ui-kit - a components based React-Native UI Kit

expo-ui-kit is a React-Native UI framework based on Expo.io SDK that will help build React-Native Expo apps using predefined & customizable UI components.

UI Components:

Tools & Utils:

  • helpers: getMargins, getPaddings, mergeTheme
  • rgba: transform hex colors into rgba colors using opacity
  • theme.js: default theme for UI components with predefined values for: COLORS, SIZES, FONTS

Block

https://reactnative.dev/docs/view

https://reactnative.dev/docs/flexbox

Usage:

  • default Block has flex: 1
  1. <Block>
  2. <Text>components</Text>
  3. </Block>
  • disable flex
  1. <Block flex="{0}">
  2. <Text>flex: 0</Text>
  3. </Block>
  4. <Block noFlex>
  5. <Text>flex: 0</Text>
  6. </Block>
  • flex for half of the size
  1. <Block flex="{0.5}">
  2. <Text>flex: 0.5</Text>
  3. </Block>
  • row will render flexDirection: row
  1. <Block row>
  2. <Text>text 1</Text>
  3. <Text>text 2</Text>
  4. </Block>
  • vertical centering the content
  1. <Block center>
  2. <Text>text 1</Text>
  3. <Text>text 2</Text>
  4. </Block>
  • horizontal centering the content
  1. <Block middle>
  2. <Text>text 1</Text>
  3. <Text>text 2</Text>
  4. </Block>
  • vertical & horizontal centering the content
  1. <Block center middle>
  2. <Text>text 1</Text>
  3. <Text>text 2</Text>
  4. </Block>

Colors

  • will render backgroundColor using predefined colors from theme.js COLORS array
  • predefined colors: primary, secondary, tertiary, black, white, gray, error, warning, success, info
  1. <Block primary>
  2. <Text>backgroundColor: COLORS.primary</Text>
  3. </Block>
  4. <Block secondary>
  5. <Text>backgroundColor: COLORS.secondary</Text>
  6. </Block>
  • custom color using hex color
  1. <Block color="#DDDDDD">
  2. <Text>backgroundColor: #DDDDDD</Text>
  3. </Block>

Arrange content using justifyContent

https://reactnative.dev/docs/layout-props#justifycontent

  • space between the content
  1. <Block space="between">
  2. <Text>1st text</Text>
  3. <Text>2nd text</Text>
  4. </Block>
  • space evenly the content
  1. <Block space="evenly">
  2. <Text>1st text</Text>
  3. <Text>2nd text</Text>
  4. </Block>
  • space around the content
  1. <Block space="around">
  2. <Text>1st text</Text>
  3. <Text>2nd text</Text>
  4. </Block>

Border radius

  • round the corners using borderRadius: 6
  1. <Block radius="{6}">
  2. <Text>1st text</Text>
  3. <Text>2nd text</Text>
  4. </Block>

Wrap content using flexWrap, default flexWrap: ‘nowrap’

https://reactnative.dev/docs/flexbox#flex-wrap

  • flexWrap: ‘wrap’
  1. <Block wrap>
  2. <Text>1st text</Text>
  3. <Text>2nd text</Text>
  4. <Text>3rd text</Text>
  5. </Block>

For animations animate props can be use to render Animated.View component

  • animated will render Animated.View
  1. <Block animated>
  2. <Text>animated view</Text>
  3. </Block>

For safe area views, safe props can be use to render SafeAreaView component

  • safe will render SafeAreaView
  1. <Block safe>
  2. <Text>safe area view</Text>
  3. </Block>

Button

https://reactnative.dev/docs/touchableopacity

https://reactnative.dev/docs/touchablehighlight

https://reactnative.dev/docs/touchablenativefeedback

https://reactnative.dev/docs/touchablewithoutfeedback

Default render an instance of TouchableOpacity

  • TouchableHighlight
  1. <button highlight>
  2. <Text>instance of TouchableHighlight</Text>
  3. </button>
  • TouchableNativeFeedback
  1. <button nativeFeedback>
  2. <Text>instance of TouchableNativeFeedback</Text>
  3. </button>
  • TouchableWithoutFeedback
  1. <button withoutFeedback>
  2. <Text>instance of TouchableWithoutFeedback</Text>
  3. </button>

Colors

  • will render backgroundColor using predefined colors from theme.js COLORS array
  • predefined colors: primary, secondary, tertiary, black, white, gray, error, warning, success, info
  1. <button primary>
  2. <Text>backgroundColor: COLORS.primary</Text>
  3. </button>
  4. <button transparent>
  5. <Text>backgroundColor: "transparent"</Text>
  6. </button>
  • custom color using hex color
  1. <button color="#DDDDDD">
  2. <Text>backgroundColor: #DDDDDD</Text>
  3. </button>

Set activeOpacity using opacity prop
default activeOpacity=0.8

  1. <button opacity="{0.5}">
  2. <Text>opacity={0.5}</Text>
  3. </button>

Outlined and add borderColor equal with backgroundColor

  1. <button primary outlined>
  2. <Text>outlined</Text>
  3. </button>

Disabling the button

  1. <button disabled>
  2. <Text>disabled</Text>
  3. </button>
  4. <button disabled="{false}">
  5. <Text>false</Text>
  6. </button>

Add flex to button style

  1. <button flex>
  2. <Text>flex=1</Text>
  3. </button>
  4. <button flex="{2}">
  5. <Text>flex=2</Text>
  6. </button>

Add height to button style

  1. <button height="{58}">
  2. <Text>height=58</Text>
  3. </button>

Card

https://reactnative.dev/docs/view

https://reactnative.dev/docs/flexbox

Using Block component with predefined props: color, radius and padding

  1. <Card>
  2. <Text>default card</Text>
  3. </Card>

Border radius using radius props

  1. <Card radius="{8}">
  2. <Text>radius={8}</Text>
  3. </Card>

Padding using padding props

  • default padding={SIZES.base}
  1. <Card padding="{12}">
  2. <Text>padding={12}</Text>
  3. </Card>

Set shadow using shadow props

  • default shadow with color black and elevation
  • shadowOffset is calculated using elevation - 1
  • shadowRadius is equal with elevation value
  1. <Card shadow>
  2. <Text>shadow</Text>
  3. </Card>
  4. <Card shadow elevation="{2}">
  5. <Text>shadow elevation={2}</Text>
  6. </Card>

Set borderColor using outlined prop

  • default borderWidth: 1 and borderColor: Utils.rgba(COLORS.black, 0.16) with alpha 0.16
  1. <Card outlined>
  2. <Text>outlined</Text>
  3. </Card>

Input

https://reactnative.dev/docs/textinput

Validation

  • onValidation return a single boolean or object with boolean values
  • pattern using regex string for validating the value
  • single pattern to validate the value
  1. <Input pattern="/\d/" // validate digits onValidation={isValid =>
  2. console.log(isValid)} />
  • multiple pattern to validate the value
  1. <Input pattern={[ "/\d/", "/\w/"]} // validate digits and words
  2. onValidation={isValid => console.log(isValid)} />

Border color using color prop

  1. <input color="red" />

Pass ref from props using internalRef reference

  1. <Input internalRef={c => this.c} />

Text

https://reactnative.dev/docs/text

Usage:

  • fontSize predefined by theme.js
  1. <Text h1>fontSize of 34 from FONTS.h1</Text>
  2. <Text h2>fontSize of 24 from FONTS.h2</Text>
  3. <Text h3>fontSize of 20 from FONTS.h3</Text>
  4. <Text title>fontSize of 18 from FONTS.title</Text>
  5. <Text subtitle>fontSize of 14 from FONTS.subtitle</Text>
  6. <Text caption>fontSize of 12 from FONTS.caption</Text>
  7. <Text small>fontSize of 10 from FONTS.small</Text>
  • fontSize defined by user
  1. <Text size="{20}">fontSize of 20</Text>
  • margin & padding
  1. <Text margin="{4}">set margin 4 to: top, right, bottom & left</Text>
  2. <Text padding="{6}">set margin 6 to: top, right, bottom & left</Text>
  • text styling
  1. <Text transform>textTransform: capitalize, lowercase, uppercase</Text>
  2. <Text regular>fontWeight from WEIGHTS.regular</Text>
  3. <Text bold>fontWeight from WEIGHTS.bold</Text>
  4. <Text semibold>fontWeight from WEIGHTS.semibold</Text>
  5. <Text medium>fontWeight from WEIGHTS.medium</Text>
  6. <Text light>fontWeight from WEIGHTS.light</Text>
  7. <Text weight="700">fontWeight from user input</Text>
  • text colors
  1. <Text primary>color from COLORS.primary</Text>
  2. <Text secondary>color from COLORS.secondary</Text>
  3. <Text tertiary>color from COLORS.tertiary</Text>
  4. <Text black>color from COLORS.black</Text>
  5. <Text white>color from COLORS.white</Text>
  6. <Text gray>color from COLORS.gray</Text>
  7. <Text info>color from COLORS.info</Text>
  8. <Text success>color from COLORS.success</Text>
  9. <Text warning>color from COLORS.warning</Text>
  10. <Text error>color from COLORS.error</Text>
  11. <Text color="#DDD">color from user input</Text>

custom theme using the src/theme.js data structure

  • create a custom theme by defining: const customTheme.js
  • with the following structure to rewrite any value
  1. {
  2. COLORS: {
  3. primary: "cyan" or "#8A00D4",
  4. secondary: "fucsia" or "#D527B7",
  5. tertiary: "yellow" or "#FFC46B"
  6. },
  7. SIZES: {
  8. font: 15,
  9. h1: 28
  10. title: 17
  11. }
  12. }
  • include the custom theme to the component props
  1. <Text primary theme="{customTheme}">primary using new color: #8A00D4</Text>
  • animating text can be used using the “animated” props
  1. <Text animated>will render Animated.Text</Text>