lodev09 / react-native-true-sheet

The true native bottom sheet experience 💩
https://sheet.lodev09.com
MIT License
394 stars 12 forks source link

Open the same sheet component from two different screens #80

Closed Luxlorys closed 1 month ago

Luxlorys commented 1 month ago

i got specific bug on IOS when using true sheet - i want to open the same sheet from screen (home page) and from another sheet (that also on the home page) so i put my true sheet component to home page and to 'parent' sheet, on Android it works fine but IOS doesn't open any of them and return this - i found only one solutionput my sheet component to the parent screen (home) and when open it from another sheet close 'parent' sheet before open new one, but is there any other solution?

Attempt to present <TrueSheet.TrueSheetViewController: 0x125d9d000> on <UIViewController: 0x106216370> (from <RNSScreen: 0x108b7bc00>) which is already presenting <TrueSheet.TrueSheetViewController: 0x107abb800>.

lodev09 commented 1 month ago

@Luxlorys can you paste your code here?

Luxlorys commented 1 month ago

// Home.tsx

export const Home = () => {
  <Box>
   <Map />
   <EventsBottomSheet />
  <EventDetailsBottomSheet />
 </Box>

// Map.tsx

export const Map = () => {
 const handleMarkerClick = (marker: MarkerT) => SheetService.open('EVENT_DETAILS_SHEET', 0);
return (
    <MapView
      ref={mapRef}
      showsCompass={false}
      provider={PROVIDER_GOOGLE}
      style={styles.flex1}
      initialCamera={{ center: initialCamera, pitch: 1, heading: 1, zoom: 13 }}>
      {markers.map((marker, index) => (
        <Marker
          key={marker.id}
          marker={marker}
          stopNumber={index + 1}
          onPress={handleMarkerClick}
        />
      ))}
    </MapView>
  );
}

// EventsBottomSheet.tsx

export const EventsBottomSheet = () => {
 const handleEventPress = () => SheetService.open('EVENT_DETAILS_SHEET', 0);

<TrueSheet
      ref={sheet}
      scrollRef={scrollRef}
      dimmed={false}
      cornerRadius={24}
      name={SHEET_NAMES.EVENTS_SHEET}
      sizes={[600]}>
// some code here for scrollview
   <TouchableOpacity onPress={}>
    <EventCard />
   </ TouchableOpacity >

 <EventDetailsBottomSheet />
</ TrueSheet>

Not all code but the logic is that i want to open from home page by clicking on marker on the map or open that sheet by clicking on event card inside

lodev09 commented 1 month ago

hmmm looks okay.. Can you create a reproducible example? You can use the example project in this repo -- it's also using maps and child sheets

Luxlorys commented 1 month ago

sorry i can't the only solution i found is to put all my sheets to root screen (Home) and close parent sheet before open child one, but this solution isn't convenient for me

lodev09 commented 1 month ago

You need to close the presenting sheet first if it's not the parent of the sheet you're trying to present. That's how IOS works, unfortunately

Luxlorys commented 1 month ago

that's the problem - i try to open new sheet which is child to EventsBottomSheet sheet and it works fine, it opens above parent as i wanted to but at the same time i want to open this sheet (child) from Home screen which is parent for EventsBottomSheet also i have bottom sheet which i want to open from 3 different bottom sheet and i'm getting the same error

Attempt to present <TrueSheet.TrueSheetViewController: 0x125d9d000> on <UIViewController: 0x106216370> (from <RNSScreen: 0x108b7bc00>) which is already presenting <TrueSheet.TrueSheetViewController: 0x107abb800>.

lodev09 commented 1 month ago

Right. you can't open other sheet outside the parent. No way around that

Luxlorys commented 1 month ago

i thought if i put this child sheet to Home screen so it becomes independent from parent sheet

Luxlorys commented 1 month ago

oh, do you mean that when i try to open it globally it doesn't understand what sheet to open because that child sheet stay belong Home screen and parent sheet at the same time?

lodev09 commented 1 month ago

You can only open 1 sheet at a time UNLESS it's a child of a the currently opened sheet. I suggest you take a look at the example project. It has example of children sheets that you can reference.

Closing this.