[iOS] `lazy` + `'content'` detent: reopening after expanding to a higher detent crashes with "Detents must be passed in ascending order"

Aperta
#132 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ios, react-native
Ambito
mobile

Direzione di ricerca

Start by tracing ModalBottomSheet detent resolution and lazy content remounting on iOS; the native stack names HostingView.resolveDetentSpecs, resolveDetentsFromLayout, and refreshDetentsFromLayout. Reproduce with detents [0, "content", "90%"], expand, close, and reopen. Done means reopening no longer fatals and the sheet opens at the content detent.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
lazy + 'content' detent: reopening after expanding to a higher detent fatals with "Detents must be passed in ascending order" (iOS)

Version: @swmansion/react-native-bottom-sheet 1.1.0
Platform: iOS simulator (iPhone 18 Pro, iOS ), New Architecture
React Native: 0.88.1 (Expo SDK 58, dev client)

Description

A ModalBottomSheet with lazy and detents [0, 'content', '90%'] works the first time. If you drag it up to the 90% detent, close it, then open it again, the app hits an RCTFatal:

Invalid bottom sheet detent at index 2: resolved position 0.9 is lower than
previous detent position 1.0. Detents must be passed in ascending order.

The content is short (a title, one line of text and a button), so 'content' should resolve far below 0.9. The same steps without lazy work every time.

Steps to reproduce
  1. Render the sheet below, inside BottomSheetProvider.
  2. Tap Open. The sheet opens at the 'content' detent. ✅
  3. Drag it up to the 90% detent. ✅
  4. Tap Close, or tap the scrim, and let it settle closed. ✅
  5. Tap Open again. 💥 Fatal error.
import { useState } from "react";
import { Button, StyleSheet, Text, View } from "react-native";
import { ModalBottomSheet } from "@swmansion/react-native-bottom-sheet";

export function Repro() {
  const [index, setIndex] = useState(0);

  return (
    <View style={{ flex: 1, justifyContent: "center" }}>
      <Button title="Open" onPress={() => setIndex(1)} />
      <ModalBottomSheet
        lazy
        index={index}
        detents={[0, "content", "90%"]}
        onIndexChange={setIndex}
        onCloseRequest={() => setIndex(0)}
        scrimColor="rgba(0, 0, 0, 0.4)"
        surface={<View style={[StyleSheet.absoluteFill, { backgroundColor: "white" }]} />}
        surfaceStyle={{ borderTopLeftRadius: 32, borderTopRightRadius: 32 }}
      >
        <View style={{ padding: 20, paddingBottom: 40, gap: 16 }}>
          <Text style={{ fontSize: 22, fontWeight: "600" }}>Native bottom sheet</Text>
          <Text>Drag up to 90%, then close and reopen.</Text>
          <Button title="Close" onPress={() => setIndex(0)} />
        </View>
      </ModalBottomSheet>
    </View>
  );
}
Expected

On reopening, the sheet opens at the 'content' detent, as it did the first time.

Actual

'content' resolves to 1.0 (full available height) when the sheet remounts, so it fails the ascending-order check against '90%' and the app crashes.

Native stack (top frames):

RCTFatal
-[BottomSheetComponentView bottomSheetView:didReportError:]
-[BottomSheetContentView bottomSheetHostingView:didReportError:]
HostingView.resolveDetentSpecs
HostingView.resolveDetentsFromLayout
HostingView.refreshDetentsFromLayout
HostingView.setDetents
-[BottomSheetContentView setDetents:]
-[BottomSheetComponentView updateProps:oldProps:]
RCTPerformMountInstructions
-[RCTMountingManager performTransaction:]
Notes
  • My guess, from the error: when lazy remounts the content, 'content' is resolved before the remounted content has its real height, possibly using the height from the last time the sheet was open at 90%.
  • Even when 'content' really is taller than a later fixed detent, a fatal error seems harsh. Clamping it, or showing a dev-only warning, would be easier to work with, since content height isn't always predictable.
  • Workaround: remove lazy.
Lingua principale
Kotlin
Stelle
536
Fork
24
Merge medio
12h 10m
PR unite (30g)
22

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di software-mansion/react-native-bottom-sheet

Tutte le issue di software-mansion/react-native-bottom-sheet

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.