Skip to content

Commit

Permalink
Refactor focus change listener to improve readability and avoid crash…
Browse files Browse the repository at this point in the history
…es (#6080)
  • Loading branch information
sonalyadav1 authored Dec 26, 2024
1 parent 75ca96a commit 4244373
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ fun placeAdapterDelegate(
showOrHideAndScrollToIfLast()
onItemClick?.invoke(item)
}
root.setOnFocusChangeListener { view1: View?, hasFocus: Boolean ->
root.setOnFocusChangeListener { _: View?, hasFocus: Boolean ->
val parentView = root.parent.parent.parent as? RelativeLayout
val bottomSheetBehavior = parentView?.let { BottomSheetBehavior.from(it) }

// Hide button layout if focus is lost, otherwise show it if it's not already visible
if (!hasFocus && nearbyButtonLayout.buttonLayout.isShown) {
nearbyButtonLayout.buttonLayout.visibility = GONE
} else if (hasFocus && !nearbyButtonLayout.buttonLayout.isShown &&
BottomSheetBehavior.from(root.parent.parent.parent as RelativeLayout).state !=
BottomSheetBehavior.STATE_HIDDEN
) {
showOrHideAndScrollToIfLast()
onItemClick?.invoke(item)
} else if (hasFocus && !nearbyButtonLayout.buttonLayout.isShown) {
if (bottomSheetBehavior?.state != BottomSheetBehavior.STATE_HIDDEN) {
showOrHideAndScrollToIfLast()
onItemClick?.invoke(item)
}
}
}
nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult) }
Expand Down

0 comments on commit 4244373

Please sign in to comment.