-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure alert dialog title wraps to two lines, uses default style (#47095
) Summary: Pull Request resolved: #47095 The [internal `DialogTitle` implementation from Android](https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/com/android/internal/widget/DialogTitle.java;l=63?q=DialogTitle) makes additional checks to see if the title should wrap to two lines before applying ellipsis, so this change recreates those same checks. This change also removes the text appearance and size changes made to the layout. Reverts some of the changes made to #45395. **Changelog:** [Android][Fixed] - Fixed styling on alert dialog titles to wrap two lines and retain bold appearance Reviewed By: cortinico Differential Revision: D64543105 fbshipit-source-id: 30d1f9091aa7216eb5d00e4f8f14cbc719c803ea
- Loading branch information
1 parent
dc737a7
commit c54b23f
Showing
2 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
.../react-native/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/DialogTitle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.modules.dialog | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.widget.TextView | ||
|
||
/** | ||
* Reimplementation of Android's internal DialogTitle. This class will attempt to render titles on | ||
* two lines if they are too long, applying ellipsis as necessary. | ||
* | ||
* @see | ||
* https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/core/java/com/android/internal/widget/DialogTitle.java | ||
*/ | ||
internal class DialogTitle : TextView { | ||
|
||
constructor( | ||
context: Context, | ||
attrs: AttributeSet, | ||
defStyleAttr: Int, | ||
defStyleRes: Int, | ||
) : super(context, attrs, defStyleAttr, defStyleRes) | ||
|
||
constructor( | ||
context: Context, | ||
attrs: AttributeSet, | ||
defStyleAttr: Int, | ||
) : super(context, attrs, defStyleAttr) | ||
|
||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) | ||
|
||
constructor(context: Context) : super(context) | ||
|
||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec) | ||
val layout = layout | ||
if (layout != null) { | ||
val lineCount = layout.lineCount | ||
if (lineCount > 0) { | ||
val ellipsisCount = layout.getEllipsisCount(lineCount - 1) | ||
if (ellipsisCount > 0) { | ||
setSingleLine(false) | ||
setMaxLines(2) | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters