jemise111 / react-native-swipe-list-view

A React Native ListView component with rows that swipe open and closed
https://www.npmjs.com/package/react-native-swipe-list-view
MIT License
2.78k stars 528 forks source link

Swiperow crashed after navigate to new view #492

Closed developerZirkonzahn closed 4 years ago

developerZirkonzahn commented 4 years ago

I use a Swiperow with 2 buttons, on one button i change view and when i go back to the previouse view my app crashes.

`<SwipeRow disableRightSwipe={true} rightOpenValue={-150} useNativeDriver={true}>
                <View style={styles.rowBack}>
                    <TouchableOpacity
                        style={[styles.backRightBtn, styles.backRightBtnLeft]}
                        onPress={() => onInfo() }
                    >
                        <Ionicons name="md-information" size={40} color='white' />
                    </TouchableOpacity>
                    <TouchableOpacity
                        style={[styles.backRightBtn, styles.backRightBtnRight]}
                        onPress={() => onDelete()}
                    >
                        <Ionicons name="md-trash" size={40} color='white' />
                    </TouchableOpacity>
                </View>
            </SwipeRow>`
jemise111 commented 4 years ago

Hey @developerZirkonzahn do you have any info about the crash, what the error message is?

developerZirkonzahn commented 4 years ago

When i run it on Expo it doesn`t thorw an error, but if i build the app on ios and run it on testflight it crashs. In the crashlog it only sasy:

Exeption Type: EXC_CRASH (SIGABRT) Exeption Note: EXC_CORPSE_NOTIFY

developerZirkonzahn commented 4 years ago

the onDelete button works how it should, it only crashes when i change screen with the onInfo button and return to the previews screen.

jemise111 commented 4 years ago

@developerZirkonzahn This is the first I'm ever hearing of this so I have a feeling this issue isn't related to this library, but happy to help you debug.. what's going on in the onInfo function?

developerZirkonzahn commented 4 years ago

i call navigation.navigate to navigate to the next view. nothing else

developerZirkonzahn commented 4 years ago

I used the old version of swipeout react-native-swipeout and everything worked fine.

In my homescreen i use a Flatlist:

<FlatList
                    data={this.state.machineList}
                    onRefresh={() => this.onRefresh()}
                    refreshing={this.state.isFetching}
                    keyExtractor={item => this._keyExtractor(item)}
                    renderItem={({ item, index }) => {
                        return (
                            <MachineListItem machine={item} index={index} 
                                onPress={() =>
                                    this.props.navigation.navigate('MachineDetailScreen', {
                                        machine: item
                                    })
                                }
                                onDelete={() => { this._removeMachine(item.unit_key) }}
                                onAd={() =>
                                    this.props.navigation.navigate("AdScreen", {
                                        link: item.link,
                                        title: item.title
                                    })
                                }
                                onInfo=
                                {() =>
                                    this.props.navigation.navigate('MachineInfoScreen', {
                                        image: item.machineImg
                                    })
                                }
                            />
                        )
                    }}
                />

I pass every Item to the class MachineListItem, where I use SwipeRow.

jemise111 commented 4 years ago

Hm I don't see anything wrong with the code. Is there anyway to run this in debug mode in Xcode and try to see more in the crash logs? Without more to go on this is tough to diagnose on this end

developerZirkonzahn commented 4 years ago

I rewrote my code and I use a SwipeListView now, but I get the same error. I think that's because I'm navigating to the next view and when I'm going back to SwipeListView, the row is still open. How can I close ah row when i press a button, bc when I use rowMap[rowData.item.key].closeRow(), rowData.item.key is undefined.

<SwipeListView
                    useNativeDriver={true}
                    data={this.state.machineList}
                    onRefresh={() => this.onRefresh()}
                    refreshing={this.state.isFetching}
                    keyExtractor={item => this._keyExtractor(item)}
                    renderItem={this._renderItem}
                    renderHiddenItem={this._renderHiddenItem}
                    rightOpenValue={-150}  
                    disableRightSwipe={true}
                />
_renderHiddenItem = (data) => (
        <View style={styles.rowBack}>
            <TouchableOpacity
                style={[styles.backRightBtn, styles.backRightBtnLeft]}
                onPress={() => {          <  ---   \\ close row here, before navigate
                    this.props.navigation.navigate('MachineInfoScreen', {
                        image: data.item.machineImg,
                        name: data.item.name,
                        serial: data.item.serial,
                        code: data.item.unit_key,
                        type: data.item.type,
                        service: data.item.services,
                        timestamp: this._calculateTime(data.item.lastCallback)
                    })
                }}
            >
                <Ionicons name="md-information" size={40} color='white' />
            </TouchableOpacity>
        </View>
    );
jemise111 commented 4 years ago

@developerZirkonzahn can you show me where in your code you're calling rowData.item.key, I don't see it above?

This should definitely be working, see here for a reference: https://github.com/jemise111/react-native-swipe-list-view/blob/master/SwipeListExample/examples/basic.js#L54

developerZirkonzahn commented 4 years ago

nvm, I could fix all my problems. thanks.