Skip to content

Commit f2f2549

Browse files
authored
fix(android): emit didFocus after parent translate animation (#666)
* fix(android): emit didFocus after parent translate animation * chore: update changelog
1 parent 461cf4a commit f2f2549

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 🐛 Bug fixes
66

7+
- **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))
78
- **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))
89

910
## 3.10.0

android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ class TrueSheetView(private val reactContext: ThemedReactContext) :
479479
* Resets this sheet's translation and restores dragging when it becomes topmost.
480480
* Parent recalculates its translation based on this sheet's position.
481481
*/
482-
fun resetTranslation() {
482+
fun resetTranslation(onTranslateEnd: (() -> Unit)? = null) {
483483
viewController.sheetView?.behavior?.isDraggable = viewController.draggable
484-
viewController.translateSheet(0)
484+
viewController.translateSheet(0, onEnd = onTranslateEnd)
485485

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

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

523-
TrueSheetStackManager.unregisterSheet(this, hadParent)
523+
TrueSheetStackManager.unregisterSheet(this)
524+
525+
parent?.resetTranslation {
526+
val parentController = parent.viewController
527+
if (parentController.isPresented && !parentController.isBeingDismissed) {
528+
parent.viewControllerDidFocus()
529+
}
530+
}
524531
}
525532

526533
override fun viewControllerDidChangeDetent(index: Int, position: Float, detent: Float) {

android/src/main/java/com/lodev09/truesheet/TrueSheetViewController.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ interface TrueSheetViewControllerDelegate {
5050
fun viewControllerWillPresent(index: Int, position: Float, detent: Float)
5151
fun viewControllerDidPresent(index: Int, position: Float, detent: Float)
5252
fun viewControllerWillDismiss()
53-
fun viewControllerDidDismiss(hadParent: Boolean)
53+
fun viewControllerDidDismiss(parent: TrueSheetView?)
5454
fun viewControllerDidChangeDetent(index: Int, position: Float, detent: Float)
5555
fun viewControllerDidDragBegin(index: Int, position: Float, detent: Float)
5656
fun viewControllerDidDragChange(index: Int, position: Float, detent: Float)
@@ -1163,12 +1163,11 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
11631163
}
11641164

11651165
private fun emitDidDismissEvents() {
1166-
val hadParent = parentSheetView != null
1167-
parentSheetView?.viewControllerDidFocus()
1166+
val parent = parentSheetView
11681167
parentSheetView = null
11691168

11701169
delegate?.viewControllerDidBlur()
1171-
delegate?.viewControllerDidDismiss(hadParent)
1170+
delegate?.viewControllerDidDismiss(parent)
11721171

11731172
dismissPromise?.invoke()
11741173
dismissPromise = null
@@ -1224,7 +1223,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
12241223
}
12251224
}
12261225

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

12301229
sheet.animate()
@@ -1234,6 +1233,7 @@ class TrueSheetViewController(private val reactContext: ThemedReactContext) :
12341233
val effectiveTop = sheet.top + sheet.translationY.toInt()
12351234
emitChangePositionDelegate(effectiveTop)
12361235
}
1236+
.withEndAction { onEnd?.invoke() }
12371237
.start()
12381238
}
12391239

android/src/main/java/com/lodev09/truesheet/core/TrueSheetStackManager.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,12 @@ object TrueSheetStackManager {
4848
}
4949

5050
/**
51-
* Unregisters a sheet from the stack and resets parent translation if needed.
51+
* Unregisters a sheet from the stack.
5252
*/
5353
@JvmStatic
54-
fun unregisterSheet(sheetView: TrueSheetView, hadParent: Boolean) {
54+
fun unregisterSheet(sheetView: TrueSheetView) {
5555
synchronized(presentedSheetStack) {
5656
presentedSheetStack.remove(sheetView)
57-
if (hadParent) {
58-
presentedSheetStack.lastOrNull()?.resetTranslation()
59-
}
6057
}
6158
}
6259

0 commit comments

Comments
 (0)