Skip to content

Index is always -1 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jamesholcomb opened this issue Apr 17, 2017 · 0 comments
Open

Index is always -1 #4

jamesholcomb opened this issue Apr 17, 2017 · 0 comments

Comments

@jamesholcomb
Copy link
Contributor

import React, { Component } from 'react'
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native'
import Ionicons from 'react-native-vector-icons/Ionicons'
import { ActionSheet, ActionSheetItem } from 'react-native-action-sheet-component'
import NavigationBar from 'react-native-navbar'

const checkedIcon = <Ionicons name="ios-checkmark-outline" size={30} />

export default class ActionSheetExample extends Component {
  constructor(props) {
    super(props)

    this.state = {
      selectedItems: [],
    }
  }

  onChange = (value, index, values) => {
    console.log('OnChange()', 'value:', value, 'index:', index, 'values:', values)
    this.setState({ selectedItems: values })
  }

  onItemPress = (value, index) => {
    console.log('OnItemPress()', 'value:', value, 'index:', index)
  }

  showActionSheet = () => {
    this.actionSheet.show()
  }

  render() {
    return (
      <View style={{ flex: 1, backgroundColor: '#DDDDDD' }}>
        <NavigationBar
          style={{ backgroundColor: '#ABC' }}
          title={{ title: 'Home' }}
          rightButton={{ title: 'Choose', handler: () => this.actionSheet.show() }}
        />
        <ActionSheet
          ref={(actionSheet) => { this.actionSheet = actionSheet }}
          position="bottom"
          onChange={this.onChange}
        >
          <ActionSheetItem
            text="Github"
            value="item1"
            index={0}
            selectedIcon={checkedIcon}
            onPress={this.onItemPress}
          />
          <ActionSheetItem
            text="Facebook"
            value="item2"
            index={1}
            selectedIcon={checkedIcon}
            onPress={this.onItemPress}
          />
        </ActionSheet>
      </View>
    )
  }
}
OnItemPress() value: item1 index: -1
OnChange() value: item1 index: -1 values: ["item1"]
OnItemPress() value: item2 index: -1
OnChange() value: item2 index: -1 values: ["item2"]

At first I thought index would be auto set by the ActionSheet, so then I tried specifying explicitly in props (see above).

Perhaps ActionSheet could set index automatically if not specified in props?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant