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

Listening to parent state changes in modal #104

Closed
mr-moto opened this issue Dec 8, 2020 · 4 comments · Fixed by #108
Closed

Listening to parent state changes in modal #104

mr-moto opened this issue Dec 8, 2020 · 4 comments · Fixed by #108
Labels
bug Something isn't working

Comments

@mr-moto
Copy link
Contributor

mr-moto commented Dec 8, 2020

Bug

May be a feature request.

Similar but slightly different to #71
Currently using react native firebase realtime listener for database changes. The parent gets the data and passes it on to the modal which displays more information. The problem is that the data passed to the modal doesn't update with new data.
Id like to avoid dismissing the modal then making is appear again to show the updated state. Am I missing something or is there a workaround for something like this?

Works fine when using <BottomSheet/> and not a modal

Thanks!

Environment info

Library Version
@gorhom/bottom-sheet 1.4.1
react-native 0.63.3
react-native-reanimated 1.13.2
react-native-gesture-handler 1.9.0

Steps To Reproduce

  1. simulate a listener changing state ( see sample code )

Describe what you expected to happen:

  1. updated state to be displayed in the modal

Reproducible sample code

// OverlayExample.tsx
import React, { useCallback, useState, useEffect } from 'react';
import { View, StyleSheet, Alert, Text } from 'react-native';
import { useBottomSheetModal, BottomSheetOverlay } from '@gorhom/bottom-sheet';
import Button from '../../components/button';
import ContactListContainer from '../../components/contactListContainer';
import withModalProvider from '../withModalProvider';

const OverlayExample = () => {
  //ADDED
  const [state, setState] = useState('unchanged');
  const { present } = useBottomSheetModal();

  //ADDED
  useEffect(() => {
    // simulate RN Firebase firestore realtime listener
    setTimeout(() => {
      setState('changed');
    }, 5000);
  }, []);

  // callbacks
  const handleChange = useCallback((index: number) => {
    if (index === 0) {
      Alert.alert('Modal Been Dismissed');
    }
  }, []);
  const handlePresentPress = useCallback(() => {
    present(
      <ContactListContainer
        title="Modal FlatList"
        type="FlatList"
        state={state} //ADDED - display the state in this component
      />,
      {
        snapPoints: [300, '50%'],
        animationDuration: 250,
        overlayComponent: BottomSheetOverlay,
        overlayOpacity: 0.75,
        dismissOnOverlayPress: true,
        onChange: handleChange,
      }
    );
  }, [present, handleChange, state]);

  // renders
  return (
    <View style={styles.container}>
      <Text>{state}</Text>
      <Button
        label="Present Modal"
        style={styles.buttonContainer}
        onPress={handlePresentPress}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 24,
  },
  buttonContainer: {
    marginBottom: 6,
  },
});

export default withModalProvider(OverlayExample);


@mr-moto mr-moto added the bug Something isn't working label Dec 8, 2020
@gorhom
Copy link
Owner

gorhom commented Dec 9, 2020

thanks @mr-moto for submitting this issue, currently i am working to rewriting the BottomSheetModal to make it more declarative 👍

please look at #75

@mr-moto
Copy link
Contributor Author

mr-moto commented Dec 9, 2020

@gorhom gotcha! Thanks for all the work your putting in!
Do you happen to have a rough timeline for when it might be released?

@gorhom
Copy link
Owner

gorhom commented Dec 9, 2020

i will try to get the next alpha release around this weekend 🤞

@gorhom
Copy link
Owner

gorhom commented Dec 13, 2020

I just released Alpha 5, it should fix this issue

yarn add @gorhom/bottom-sheet@2.0.0-alpha.5

also check out the new documents website ( still in progress ) 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants