Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### 🐛 Bug fixes

- **Android**: Emit `onDidFocus` after the parent's translate-up animation completes when a stacked child sheet is dismissed. ([#666](https://github.com/lodev09/react-native-true-sheet/pull/666) by [@lodev09](https://github.com/lodev09))
- **Android**: Fixed focused input in sheet causing auto-focus on main screen input after dismiss. ([#649](https://github.com/lodev09/react-native-true-sheet/pull/649) by [@lodev09](https://github.com/lodev09))

## 3.10.0
Expand Down
15 changes: 11 additions & 4 deletions android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
* Resets this sheet's translation and restores dragging when it becomes topmost.
* Parent recalculates its translation based on this sheet's position.
*/
fun resetTranslation() {
fun resetTranslation(onTranslateEnd: (() -> Unit)? = null) {
viewController.sheetView?.behavior?.isDraggable = viewController.draggable
viewController.translateSheet(0)
viewController.translateSheet(0, onEnd = onTranslateEnd)

// Parent should recalculate its translation based on this sheet's position
val mySheetTop = viewController.detentCalculator.getSheetTopForDetentIndex(viewController.currentDetentIndex)
Expand Down Expand Up @@ -510,7 +510,7 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
eventDispatcher?.dispatchEvent(WillDismissEvent(surfaceId, id))
}

override fun viewControllerDidDismiss(hadParent: Boolean) {
override fun viewControllerDidDismiss(parent: TrueSheetView?) {
// Detach coordinator from the root container view
viewController.coordinatorLayout?.let { rootContainerView?.removeView(it) }
rootContainerView = null
Expand All @@ -520,7 +520,14 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
val surfaceId = UIManagerHelper.getSurfaceId(this)
eventDispatcher?.dispatchEvent(DidDismissEvent(surfaceId, id))

TrueSheetStackManager.unregisterSheet(this, hadParent)
TrueSheetStackManager.unregisterSheet(this)

parent?.resetTranslation {
val parentController = parent.viewController
if (parentController.isPresented && !parentController.isBeingDismissed) {
parent.viewControllerDidFocus()
}
}
}

override fun viewControllerDidChangeDetent(index: Int, position: Float, detent: Float) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface TrueSheetViewControllerDelegate {
fun viewControllerWillPresent(index: Int, position: Float, detent: Float)
fun viewControllerDidPresent(index: Int, position: Float, detent: Float)
fun viewControllerWillDismiss()
fun viewControllerDidDismiss(hadParent: Boolean)
fun viewControllerDidDismiss(parent: TrueSheetView?)
fun viewControllerDidChangeDetent(index: Int, position: Float, detent: Float)
fun viewControllerDidDragBegin(index: Int, position: Float, detent: Float)
fun viewControllerDidDragChange(index: Int, position: Float, detent: Float)
Expand Down Expand Up @@ -1163,12 +1163,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
}

private fun emitDidDismissEvents() {
val hadParent = parentSheetView != null
parentSheetView?.viewControllerDidFocus()
val parent = parentSheetView
parentSheetView = null

delegate?.viewControllerDidBlur()
delegate?.viewControllerDidDismiss(hadParent)
delegate?.viewControllerDidDismiss(parent)

dismissPromise?.invoke()
dismissPromise = null
Expand Down Expand Up @@ -1224,7 +1223,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
}
}

fun translateSheet(translationY: Int) {
fun translateSheet(translationY: Int, onEnd: (() -> Unit)? = null) {
val sheet = sheetView ?: return

sheet.animate()
Expand All @@ -1234,6 +1233,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
val effectiveTop = sheet.top + sheet.translationY.toInt()
emitChangePositionDelegate(effectiveTop)
}
.withEndAction { onEnd?.invoke() }
.start()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@ object TrueSheetStackManager {
}

/**
* Unregisters a sheet from the stack and resets parent translation if needed.
* Unregisters a sheet from the stack.
*/
@JvmStatic
fun unregisterSheet(sheetView: TrueSheetView, hadParent: Boolean) {
fun unregisterSheet(sheetView: TrueSheetView) {
synchronized(presentedSheetStack) {
presentedSheetStack.remove(sheetView)
if (hadParent) {
presentedSheetStack.lastOrNull()?.resetTranslation()
}
}
}

Expand Down
Loading