Skip to content
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

Change Actionsheet title with state value #85

Open
sourish opened this issue Aug 14, 2019 · 0 comments
Open

Change Actionsheet title with state value #85

sourish opened this issue Aug 14, 2019 · 0 comments

Comments

@sourish
Copy link

sourish commented Aug 14, 2019

  1. I have a Flatlist, Inside the renderItem method I have Actionsheet & the code is below:

    renderItem = ({ item }) => (
    <TouchableOpacity onLongPress={() => {this.longPressed(item)}} activeOpacity={0.5} onPress={() => this.actionOnRow(item)} underlayColor="white">


    <ActionSheet
    ref={o => this.ActionSheet = o}
    title={this.getTitle()}
    options={['Generate', 'Delete', 'Cancel']}
    cancelButtonIndex={2}
    destructiveButtonIndex={2}
    onPress={(index) => {
    if (index == 0) {
    this.generate(this.state.selectedListing)
    }
    if (index == 1) {
    this.delete(this.state.selectedListing)
    }
    }}
    />
    )
    getTitle() {
    return this.state.selectedProfileName
    }

"getTitle" method return's the profile name from the selected Cell in Flatlist.
But for me here In Actionsheet the title is not being displayed.
I have also binded the "getTitle" method in constructor.

  1. The "getTitle()" method is getting called till the number of flatlist items.

Can someone please suggest me How to go further for displaying the title in ActionSheet?

UPDATED:

  1. Can I have access of item inside "<Actionsheet"

UPDATED:
In Render method

  <FlatList
  data={this.state.data}
  renderItem={this.renderItem}
  keyExtractor={item => item.id}
  ItemSeparatorComponent={this.flatListItemSeparator}
  ListFooterComponent={this.renderFooter}
  // onRefresh={this.handleRefresh}
  refreshing={this.state.refreshing}
  onEndReached={this.handleLoadMore}
  onEndReachedThreshold={0}
  onRefresh={this.refreshProfiles}
/>

After the list is generated from flatlist, When I longpress the flatlist item I want to show two options on Actionsheet

In Cell longpress method I am updating the state value & I am trying to trigger the Actionsheet as like below

longPressed(item) {
    console.log("Long pressed " + JSON.stringify(item)
    this.setState({
      selectedProfileName: item.name
    },() => {
      console.log("selected Listing "+ this.state.selectedProfileName)
      this.ActionSheet.show()
    })
  }

The JSON response is :
{ "id": 985646, "name": "Business Name", "website": "businesswebsite.com", "formatted_website": "businesswebsite.com", "is_favorite": false }

In setstate completion I am calling the actionsheet's show() method. After updating the state value also, the profile name is not been showed in Actionsheet title.

Can someone plz help me to fix this

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