0.0.2 • Published 8 years ago

react-native-context-menu-strip v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

react-native-context-menu-strip

  npm version  

A ContextMenuStrip component for react-native, Inspired from react-native-action-button

react-native-context-menu-strip example

Installation

npm i react-native-context-menu-strip --save

Usage

import ContextMenuStrip from 'react-native-context-menu-strip'

ContextMenuStrip

ContextMenuStrip component is the main component.

props
propdefaulttypedescription
autoInactivetruebooleanAuto hide ContextMenu when ContextMenuStrip.Item is pressed
width60numberwidth of menu button
height48numberheight of menu button
circleRadius40numberradius of circle which wrap '+' icon
itemWidth150numberwidth of item button
itemHeight38numberheight of item button
itemType'highlight''opacity' or 'highlight'type of item button
itemBgColor'transparent'stringbackgroundColor of item
itemUnderlayColor'#F8F7F7'stringunderlayColor of item
btnUnderlayColor'#F8F7F7'stringunderlayColor of menu's main button
btnColor'transparent'stringbackgroundColor of menu's main button, (must be rgba value!)
btnColorRangeundefinedstringbackgroundColor of menu's main button when menu opened, (must be rgba value!)
degrees135numberdegrees to rotate icon when menu opened
scaleRangeundefinednumberscale to resize menu's main button
menuBorderColor'#D5D5D5'stringborderColor of menu
menuMarginRight0numbermarginRight of menu items
menuMarginTop0numbermarginTop of menu items
iconundefinedcomponent'+' icon
onPress() = {}functioncallback when menu's main button is pressed
onResetundefinedfunctioncallback when menu reset
ContextMenuStrip.Item

ContextMenuStrip.Item specifies a menu Button.

props
propdefaulttypedescription
customizedfalsebooleanwhen customize === false, you need to specify icon and label, when customize === false, you need to specify a child component.
btnColorundefinedstringbackground color of item button
onPressundefinedfunctioncallback when item button is pressed
iconSize20numberradius of icon on item button
itemWidth150numberwidth of item button
iconNameundefinednumber or stringsource of Image component or iconName of react-native-vector-icon's component
iconTypeundefinedPropTypes.oneOf('Zocial', 'Octicons', 'MaterialIcons', 'Ionicons', 'Foundation', 'EvilIcons', 'Entypo', 'FontAwesome', 'Image')type of icon
labelundefinedstringlabel on item button

Example

The following example can be found in example.

import React, { Component } from 'react';
import {
  AppRegistry,
  BackAndroid,
  Platform,
  Text,
  View,
  Image,
} from 'react-native';
import ContextMenuStrip from 'react-native-context-menu-strip'

class example extends Component {
  contextMenuStrip

  constructor (props) {
    super(props)
    this.state = {
      menuActive: false,
    }
  }

  onMenuToggled (expand) {
    this.setState({menuActive: expand})
  }

  componentDidMount () {
    BackAndroid.addEventListener('hardwareBackPress', () => this.handleBackButton())
  }

  componentWillUnmount () {
    BackAndroid.removeEventListener('hardwareBackPress', () => this.handleBackButton())
  }

  handleBackButton () {
    if (this.state.menuActive) {
      this.setState({
        menuActive: false,
      })
      this.contextMenuStrip.reset()
      return true
    }

    // navigator

    // finally
    return false
  }

  render() {
    return (
      <ContextMenuStrip
        ref={(c) => this.contextMenuStrip = c}
        width={60}
        height={Platform.OS === 'ios' ? 40 : 48}
        itemWidth={150}
        itemHeight={38}
        btnSize={40}
        degrees={135}
        scaleRange={1.5}
        btnColorRange="rgba(88,66,77,0.8)"
        menuMarginRight={10}
        onPress={() => this.onMenuToggled(true)}
        onReset={() => this.onMenuToggled(false)}>

        {/*Icon*/}
        <ContextMenuStrip.Item
          iconType="FontAwesome"
          iconName="comments"
          label="chat"
          onPress={() => {}}
        />
        <ContextMenuStrip.Item
          iconType="FontAwesome"
          iconName="gear"
          label="setting"
          onPress={() => {}}
        />
        <ContextMenuStrip.Item
          iconType="FontAwesome"
          iconName="refresh"
          label="refresh"
          onPress={() => {}}
        />

        {/*Image Icon*/}
        <ContextMenuStrip.Item
          iconType="Image"
          iconName={require('./icons/about.png')}
          label="about"
          onPress={() => {}}
        />

        {/*Customize*/}
        <ContextMenuStrip.Item
          customized={true}
          onPress={() => {}}>
          <View style={{
            flex: 1,
            flexDirection: 'row',
            justifyContent: 'flex-start',
            alignItems: 'center',
          }}>
            <View style={{
              width: 45,
              flexDirection: 'row',
              justifyContent: 'center',
              alignItems: 'center',
            }}>
              <Image
                style={{
                  width: 20,
                  height: 20,
                  flexDirection: 'row',
                  justifyContent: 'center',
                  alignItems: 'center',
                  marginLeft: 5,
                }}
                source={require('./icons/chat.png')}
              />
            </View>

            <Text
              style={{
                flexDirection: 'row',
                justifyContent: 'center',
                alignItems: 'center',
                marginLeft: 5,
              }}
            >
              Come on
            </Text>
          </View>
        </ContextMenuStrip.Item>

      </ContextMenuStrip>
    )
  }
}


AppRegistry.registerComponent('example', () => example)