Skip to content

Commit 8c90f81

Browse files
sbuggaymeta-codesync[bot]
authored andcommitted
Improve DevMenu for Android 11 (facebook#54023)
Summary: Pull Request resolved: facebook#54023 Android 12 introduced a new AlertDialog that better fits a longer list of content. Android 11 and earlier have an AlertDialog that has a very small list view, requiring users to scroll through to find what they need. This change also fixes Android 12+ enable/disable states on menu items, as it no longer uses `isEnabled` for styling. Before: {F1982416953} After: {F1982416486} Android 12: {F1982430956} Changelog: [Internal] Reviewed By: shwanton Differential Revision: D83688775 fbshipit-source-id: a96120142f648e849be670bde5897c884f1f5f52
1 parent 6e8fab9 commit 8c90f81

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,14 @@ public abstract class DevSupportManagerBase(
543543
!disabledItemKeys.contains(getItem(position))
544544

545545
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View =
546-
super.getView(position, convertView, parent).apply { isEnabled = isEnabled(position) }
546+
super.getView(position, convertView, parent).apply {
547+
isEnabled = isEnabled(position)
548+
if (this is TextView) {
549+
setTextColor(
550+
if (isEnabled) android.graphics.Color.WHITE else android.graphics.Color.GRAY
551+
)
552+
}
553+
}
547554
}
548555

549556
devOptionsDialog =
@@ -558,6 +565,24 @@ public abstract class DevSupportManagerBase(
558565

559566
devOptionsDialog?.show()
560567

568+
// Prior to Android 12, the list view in AlertDialogs did not match
569+
// their content size.
570+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
571+
devOptionsDialog?.getListView()?.let { listView ->
572+
val displayMetrics = context.resources.displayMetrics
573+
val maxHeight = (displayMetrics.heightPixels * 0.7).toInt()
574+
575+
val layoutParams =
576+
listView.layoutParams
577+
?: ViewGroup.LayoutParams(
578+
ViewGroup.LayoutParams.MATCH_PARENT,
579+
ViewGroup.LayoutParams.WRAP_CONTENT,
580+
)
581+
layoutParams.height = maxHeight
582+
listView.layoutParams = layoutParams
583+
}
584+
}
585+
561586
val reactContext = currentReactContext
562587
reactContext?.getJSModule(RCTNativeAppEventEmitter::class.java)?.emit("RCTDevMenuShown", null)
563588
}

0 commit comments

Comments
 (0)