Skip to content

Commit c967dea

Browse files
committed
Revert "Fix Android AlertFragment Title Accessibility (#45395)"
This reverts commit 80a3ed7.
1 parent 55671c0 commit c967dea

File tree

3 files changed

+5
-80
lines changed

3 files changed

+5
-80
lines changed

packages/react-native/ReactAndroid/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ android {
557557
listOf(
558558
"src/main/res/devsupport",
559559
"src/main/res/shell",
560-
"src/main/res/views/alert",
561560
"src/main/res/views/modal",
562561
"src/main/res/views/uimanager"))
563562
java.exclude("com/facebook/react/processing")

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/AlertFragment.java

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,11 @@
1212
import android.content.Context;
1313
import android.content.DialogInterface;
1414
import android.content.res.TypedArray;
15-
import android.os.Build;
1615
import android.os.Bundle;
17-
import android.view.LayoutInflater;
18-
import android.view.View;
19-
import android.widget.TextView;
2016
import androidx.annotation.Nullable;
2117
import androidx.appcompat.app.AlertDialog;
22-
import androidx.core.view.AccessibilityDelegateCompat;
23-
import androidx.core.view.ViewCompat;
24-
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
2518
import androidx.fragment.app.DialogFragment;
26-
import com.facebook.infer.annotation.Assertions;
2719
import com.facebook.infer.annotation.Nullsafe;
28-
import com.facebook.react.R;
2920

3021
/** A fragment used to display the dialog. */
3122
@Nullsafe(Nullsafe.Mode.LOCAL)
@@ -75,55 +66,15 @@ private static boolean isAppCompatTheme(Context activityContext) {
7566
return isAppCompat;
7667
}
7768

78-
/**
79-
* Creates a custom dialog title View that has the role of "Heading" and focusable for
80-
* accessibility purposes.
81-
*
82-
* @returns accessible TextView title
83-
*/
84-
private static View getAccessibleTitle(Context activityContext, String titleText) {
85-
LayoutInflater inflater = LayoutInflater.from(activityContext);
86-
87-
// This layout matches the sizing and styling of AlertDialog's title_template (minus the icon)
88-
// since the whole thing gets tossed out when setting a custom title
89-
View titleContainer = inflater.inflate(R.layout.alert_title_layout, null);
90-
91-
TextView accessibleTitle =
92-
Assertions.assertNotNull(titleContainer.findViewById(R.id.alert_title));
93-
accessibleTitle.setText(titleText);
94-
accessibleTitle.setFocusable(true);
95-
96-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
97-
accessibleTitle.setAccessibilityHeading(true);
98-
} else {
99-
ViewCompat.setAccessibilityDelegate(
100-
accessibleTitle,
101-
new AccessibilityDelegateCompat() {
102-
@Override
103-
public void onInitializeAccessibilityNodeInfo(
104-
View view, AccessibilityNodeInfoCompat info) {
105-
super.onInitializeAccessibilityNodeInfo(accessibleTitle, info);
106-
info.setHeading(true);
107-
}
108-
});
109-
}
110-
111-
return titleContainer;
112-
}
113-
11469
/**
11570
* Creates a dialog compatible only with AppCompat activities. This function should be kept in
11671
* sync with {@link createAppDialog}.
11772
*/
11873
private static Dialog createAppCompatDialog(
11974
Context activityContext, Bundle arguments, DialogInterface.OnClickListener fragment) {
120-
AlertDialog.Builder builder = new AlertDialog.Builder(activityContext);
75+
AlertDialog.Builder builder =
76+
new AlertDialog.Builder(activityContext).setTitle(arguments.getString(ARG_TITLE));
12177

122-
if (arguments.containsKey(ARG_TITLE)) {
123-
String title = Assertions.assertNotNull(arguments.getString(ARG_TITLE));
124-
View accessibleTitle = getAccessibleTitle(activityContext, title);
125-
builder.setCustomTitle(accessibleTitle);
126-
}
12778
if (arguments.containsKey(ARG_BUTTON_POSITIVE)) {
12879
builder.setPositiveButton(arguments.getString(ARG_BUTTON_POSITIVE), fragment);
12980
}
@@ -154,13 +105,10 @@ private static Dialog createAppCompatDialog(
154105
@Deprecated(since = "0.75.0", forRemoval = true)
155106
private static Dialog createAppDialog(
156107
Context activityContext, Bundle arguments, DialogInterface.OnClickListener fragment) {
157-
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(activityContext);
108+
android.app.AlertDialog.Builder builder =
109+
new android.app.AlertDialog.Builder(activityContext)
110+
.setTitle(arguments.getString(ARG_TITLE));
158111

159-
if (arguments.containsKey(ARG_TITLE)) {
160-
String title = Assertions.assertNotNull(arguments.getString(ARG_TITLE));
161-
View accessibleTitle = getAccessibleTitle(activityContext, title);
162-
builder.setCustomTitle(accessibleTitle);
163-
}
164112
if (arguments.containsKey(ARG_BUTTON_POSITIVE)) {
165113
builder.setPositiveButton(arguments.getString(ARG_BUTTON_POSITIVE), fragment);
166114
}

packages/react-native/ReactAndroid/src/main/res/views/alert/layout/alert_title_layout.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)