0.0.2 • Published 7 years ago

react-natvie-purple v0.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

react-native-purple FrameWork

##写在前面 继purple-net后基于react-native 实现react-native-purple框架(代码风格参考 react-native-elements

UI TookIt util

Get Started

If you are using Exponent, you can run npm i react-native-purple --save and skip to step 3.

Step 1

Install react-native-vector-icons (if you do not already have it)

npm i react-native-vector-icons --save && react-native link react-native-vector-icons

If you have any issues with icons not working or installation of React Native Vector Icons, check out their installation guide here

Step 2

Install React Native Purple

npm i react-native-purple --save

or

yarn add react-native-purple

Step 3

Start using components

import {
  PurpleButton
} from 'react-native-purple'

< PurpleButton
  raised
  icon={{name: 'cached'}}
  title='RAISED WITH ICON' />
<PurpleButton
  raised
  icon={{name: 'cached'}}
  title='RAISED WITH ICON'
  fontFamily='Comic Sans MS' />

API

Buttons

Buttons take a title and an optional material icon name, as well as the props below.

You can override Material icons with one of the following: zocial, font-awesome, octicon, ionicon, foundation, evilicon, or entypo by providing an icon.type as a prop.

Buttons

import { Button } from 'react-native-purple'

<PurpleButton
  title='BUTTON' />

<PurpleButton
  raised
  icon={{name: 'cached'}}
  title='BUTTON WITH ICON' />

<PurpleButton
  large
  iconRight
  icon={{name: 'code'}}
  title='LARGE WITH RIGHT ICON' />

<PurpleButton
  large
  icon={{name: 'envira', type: 'font-awesome'}}
  title='LARGE WITH RIGHT ICON' />

<PurpleButton
  large
  icon={{name: 'squirrel', type: 'octicon', buttonStyle: styles.someButtonStyle }}
  title='OCTICON' />

PurpleButton props

Also recevies all TouchableWithoutFeedback props

propdefaulttypedescription
ComponentTouchableHighlight (iOS), TouchableNativeFeedback (android)React Native ComponentSpecify other component such as TouchableOpacity or other (optional)
buttonStylenoneobject (style)add additional styling for button component (optional)
titlenonestringbutton title (required)
largefalsebooleanmakes button large
fontFamilySystem font (iOS), Roboto (android)stringspecify different font family
fontWeightnonestringspecify font weight for title (optional)
iconRightfalsebooleanmoves icon to right of title
onPressnonefunctiononPress method (required)
icon{color: 'white'}object {name: string, color: string, size: number, type: string (default is material, or choose one of zocial, font-awesome, octicon, ionicon, foundation, evilicon, or entypo), style: object(style)}icon configuration (optional)
backgroundColor#397af8string (color)background color of button (optional)
borderRadiusnonenumberadds border radius to card (optional)
colorwhitestring(color)font color (optional)
textStylenoneobject (style)text styling (optional)
fontSize18numberfont size (optional)
underlayColortransparentstring(color)underlay color for button press (optional)
raisedfalsebooleanflag to add raised button styling (optional)
disabledfalsebooleanprop to indicate button is disabled (optional)

Social Icons & Buttons

Social Icons

import { SocialIcon } from 'react-native-purple'

// Icon
<SocialIcon
  type='twitter'
/>

<SocialIcon
  raised={false}
  type='gitlab'
/>

<SocialIcon
  light
  type='medium'
/>

<SocialIcon
  light
  raised={false}
  type='medium'
/>


// Button
<SocialIcon
  title='Sign In With Facebook'
  button
  type='facebook'
/>

<SocialIcon
  title='Some Twitter Message'
  button
  type='twitter'
/>

<SocialIcon
  button
  type='medium'
/>


<SocialIcon
  button
  light
  type='instagram'
/>

SocialIcon props

propdefaulttypedescription
titlenonestringtitle if made into a button (optional)
typenonesocial media type (facebook, twitter, google-plus-official, pinterest, linkedin, youtube, vimeo, tumblr, instagram, quora, foursquare, wordpress, stumbleupon, github, github-alt, twitch, medium, soundcloud, gitlab, angellist, codepen)social media type (required)
raisedtruebooleanraised adds a drop shadow, set to false to remove
buttonfalsebooleancreates button (optional)
onPressnonefunctiononPress method (optional)
lightfalsebooleanreverses icon color scheme, setting background to white and icon to primary color
iconStylenoneobject (style)extra styling for icon component (optional)
stylenoneobject (style)button styling (optional)
iconColorwhitestringicon color (optional)
iconSize24numbericon size (optional)
componentTouchableHighlightReact Native Componenttype of button (optional)
fontFamilySystem font bold (iOS), Roboto-Black (android)stringspecify different font family (optional)
fontWeightbold (ios), black(android)stringspecify font weight of title if set as a button with a title
fontStylenoneobject (style)specify text styling (optional)
disabledfalsebooleandisable button (optional)
loadingfalsebooleanshows loading indicator (optional)

Icons & Icon Buttons

Icons

Icons take the name of a material icon as a prop.

You can override Material icons with one of the following: font-awesome, octicon, ionicon, foundation, evilicon, zocial, or entypo by providing a type prop.

Hint: use reverse to make your icon look like a button

import { Icon } from 'react-native-purple'

<Icon
  name='rowing' />

<Icon
  name='g-translate'
  color='#00aced' />

<Icon
  name='sc-telegram'
  type='evilicon'
  color='#517fa4'
/>

<Icon
  reverse
  name='ios-american-football'
  type='ionicon'
  color='#517fa4'
/>

<Icon
  raised
  name='heartbeat'
  type='font-awesome'
  color='#f50'
  onPress={() => console.log('hello')} />

Icon props

propdefaulttypedescription
namenonestringname of icon (required)
typematerialstringtype (defaults to material, options are zocial, font-awesome, octicon, ionicon, foundation, evilicon, or entypo)
size26numbersize of icon (optional)
colorblackstringcolor of icon (optional)
iconStyleinherited styleobject (style)additional styling to icon (optional)
componentView if no onPress method is defined, TouchableHighlight if onPress method is definedReact Native componentupdate React Native Component (optional)
onPressnonefunctiononPress method for button (optional)
underlayColoricon colorstringunderlayColor for press event
reversefalsebooleanreverses color scheme (optional)
raisedfalsebooleanadds box shadow to button (optional)
containerStyleinherited stylingobject (style)add styling to container holding icon (optional)
reverseColorwhitestringspecify reverse icon color (optional)

Lists

Lists

Using Map Function. Implemented with avatar.

import { List, ListItem } from 'react-native-purple'

const list = [
  {
    name: 'Amy Farha',
    avatar_url: 'https://s3.amazonaws.com/uifaces/faces/twitter/ladylexy/128.jpg',
    subtitle: 'Vice President'
  },
  {
    name: 'Chris Jackson',
    avatar_url: 'https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg',
    subtitle: 'Vice Chairman'
  },
  ... // more items
]

<List containerStyle={{marginBottom: 20}}>
  {
    list.map((l, i) => (
      <ListItem
        roundAvatar
        avatar={{uri:l.avatar_url}}
        key={i}
        title={l.name}
      />
    ))
  }
</List>

Using Map Function. Implemented with link and icon.

import { List, ListItem } from 'react-native-purple'

const list = [
  {
    title: 'Appointments',
    icon: 'av-timer'
  },
  {
    title: 'Trips',
    icon: 'flight-takeoff'
  },
  ... // more items
]

<List>
  {
    list.map((item, i) => (
      <ListItem
        key={i}
        title={item.title}
        leftIcon={{name: item.icon}}
      />
    ))
  }
</List>

Using RN ListView. Implemented with link and avatar.

import { List, ListItem } from 'react-native-purple'

const list = [
  {
    name: 'Amy Farha',
    avatar_url: 'https://s3.amazonaws.com/uifaces/faces/twitter/ladylexy/128.jpg',
    subtitle: 'Vice President'
  },
  {
    name: 'Chris Jackson',
    avatar_url: 'https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg',
    subtitle: 'Vice Chairman'
  },
  ... // more items
]

renderRow (rowData, sectionID) {
  return (
    <ListItem
      roundAvatar
      key={sectionID}
      title={rowData.name}
      subtitle={rowData.subtitle}
      avatar={{uri:rowData.avatar_url}}
    />
  )
}

render () {
  return (
    <List>
      <ListView
        renderRow={this.renderRow}
        dataSource={this.state.dataSource}
      />
    </List>
  )
}

List Props

propdefaulttypedescription
containerStylemarginTop: 20, borderTopWidth: 1, borderBottomWidth: 1, borderBottomColor: #cbd2d9object (style)style the list container

ListItem props

propdefaulttypedescription
avatarnoneobjectleft avatar (optional). Refer to React Native Image Source
avatarStylenoneobject (style)avatar styling (optional)
chevronColor#bdc6cfstringset chevron color
componentView or TouchableHighlight if onPress method is added as propReact Native elementreplace element with custom element (optional)
containerStylenoneobject (style)additional main container styling (optional)
hideChevronfalsebooleanset if you do not want a chevron (optional)
leftIconnoneobject {name, color, style, type} (type defaults to material icons)icon configuration for left icon (optional)
rightIcon{name: 'chevron-right'}object {name, color, style, type} (type defaults to material icons)right icon (optional), will only show up if there is an onPress method attached (material icon name)
onPressnonefunctiononPress method for link (optional)
roundAvatarfalsebooleanmake left avatar round
subtitlenonestringsubtitle text (optional)
subtitleContainerStylenonestyle (object)provide styling for subtitle container
subtitleStylenoneobject (style)additional subtitle styling (optional )
titlenonestringmain title for list item (required)
titleStylenoneobject (style)additional title styling (optional)
wrapperStylenoneobject (style)additional wrapper styling (optional)
underlayColorwhitestringdefine underlay color for TouchableHighlight (optional)
fontFamilyHelevticaNeue (iOS), Roboto (android)stringspecify different font family
rightTitlenonestringprovide a rightTitle to have a title show up on the right side of the button, will override any icon on the right
rightTitleContainerStyleflex: 1, alignItems: 'flex-end', justifyContent: 'center'object (style)style the outer container of the rightTitle text
rightTitleStylemarginRight: 5, color: '#bdc6cf'object (style)style the text of the right text