oblador / react-native-collapsible

Animated collapsible component for React Native, good for accordions, toggles etc
MIT License
2.45k stars 451 forks source link

Adding to the touchableProps onPress functionality? #314

Closed technicallyty closed 5 years ago

technicallyty commented 5 years ago

What I'm Trying To Do:

I want to add on to the onPress of the components in the accordion, but using "touchableProps" and defining a onPress event, removes the functionality of opening them up.

Why I'm Doing this?

I want onPress to trigger another event, other than opening the accordion.

What I've tried:

    <Accordion
        touchableProps={{ onPress () {
        console.log('test')}}}
    />

This logs test, but no longer opens the accordions. Is there any way I can have onPress do multiple things?

iRoachie commented 5 years ago

What's your use case for this? Cause you can put your code in the onChange

technicallyty commented 5 years ago

Hi iRoachie, thanks for the response! My use case is this:

I have the possibility of about 200+ objects coming through to my accordion view. They get to my code via sockets. The websocket coll to the API for the names of these things is lightning fast. Less than 100ms. However, to get the individual information (each object can contain about 10 or 15 categories of info) it is much slower, as i have to query each object one by one.

So instead of just getting ALL the possible data in one go, I only want to ask the websocket to get the category data, once the user has clicked on a particular object.

Visual example

-car1-
-car2-
-car3-
-boat1-
-airplane6-

//Clicking on one of these will expand it 

-car1-
| make: jeep
| model: cherokee
| year: 1990
| damages?
|| -Front tire blown
|| -radiator broken
| Accident record
-car2-
iRoachie commented 5 years ago

See this video i made on how to do this using onPress https://www.loom.com/share/e97dde841afb404da3bda216d17becd1

technicallyty commented 5 years ago

Ah, got it working, thank you!