react-native-navigation 8.8.8 → 8.8.9-snapshot.2628
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,7 +18,6 @@ import static com.reactnativenavigation.utils.UiUtils.dpToPx;
|
|
|
18
18
|
|
|
19
19
|
@SuppressLint("ViewConstructor")
|
|
20
20
|
public class TitleBarReactButtonView extends ReactView {
|
|
21
|
-
private static final float FINAL_WIDTH_PADDING_DP = 1f;
|
|
22
21
|
private final ComponentOptions component;
|
|
23
22
|
|
|
24
23
|
public TitleBarReactButtonView(Context context, ComponentOptions component) {
|
|
@@ -45,27 +44,23 @@ public class TitleBarReactButtonView extends ReactView {
|
|
|
45
44
|
this.setId(View.NO_ID);
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
// Width: bounded (AT_MOST) so the hosted React surface sizes itself to its content. Under
|
|
48
|
+
// Fabric, ReactSurfaceView reports max-of-children under AT_MOST (the laid-out content width)
|
|
49
|
+
// and pushes that to the async layout. Crucially we must NOT push a forced EXACTLY *width*:
|
|
50
|
+
// before the content has laid out that width is collapsed (~1px), Fabric lays the content into
|
|
51
|
+
// it and the button never recovers (#8320/#8326 did this and regressed under the New Arch).
|
|
52
|
+
//
|
|
53
|
+
// Height: bounded (AT_MOST) so the surface sizes to its content height. The view is then
|
|
54
|
+
// centered vertically by the toolbar's action-view layout and the CENTER_VERTICAL gravity set
|
|
55
|
+
// in onViewAdded(). Forcing EXACTLY the full bar height (as #8328 did) made the surface fill
|
|
56
|
+
// the bar, so content-hugging buttons that don't self-center (plain text like "Publish", a
|
|
57
|
+
// fixed-size avatar image) were pinned to the top. AT_MOST height does NOT cause the width
|
|
58
|
+
// collapse — only a forced EXACTLY *width* does.
|
|
59
|
+
int widthSpec = component.width.hasValue()
|
|
49
60
|
? createExactSpec(component.width)
|
|
50
61
|
: makeMeasureSpec(resolveAvailableWidth(widthMeasureSpec), AT_MOST);
|
|
51
|
-
int
|
|
52
|
-
|
|
53
|
-
// First discover the content size without forcing every custom button to actionBarSize.
|
|
54
|
-
super.onMeasure(initialWidthSpec, initialHeightSpec);
|
|
55
|
-
|
|
56
|
-
if (component.width.hasValue() && component.height.hasValue()) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Then give RN/Yoga a stable exact final box for compatibility with centered button layouts.
|
|
61
|
-
// A small allowance avoids clipping implicit RN padding/subpixel layout while staying content-based.
|
|
62
|
-
int finalWidth = component.width.hasValue()
|
|
63
|
-
? MeasureSpec.getSize(initialWidthSpec)
|
|
64
|
-
: resolveFinalWidth(getMeasuredWidth());
|
|
65
|
-
int finalHeight = component.height.hasValue()
|
|
66
|
-
? MeasureSpec.getSize(initialHeightSpec)
|
|
67
|
-
: Math.max(getMeasuredHeight(), 1);
|
|
68
|
-
super.onMeasure(makeMeasureSpec(finalWidth, EXACTLY), makeMeasureSpec(finalHeight, EXACTLY));
|
|
62
|
+
int heightSpec = createHeightSpec(heightMeasureSpec, component.height);
|
|
63
|
+
super.onMeasure(widthSpec, heightSpec);
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
private int createHeightSpec(int measureSpec, Number dimension) {
|
|
@@ -81,10 +76,6 @@ public class TitleBarReactButtonView extends ReactView {
|
|
|
81
76
|
return availableSize > 0 ? availableSize : Math.max(getResources().getDisplayMetrics().widthPixels, 1);
|
|
82
77
|
}
|
|
83
78
|
|
|
84
|
-
private int resolveFinalWidth(int measuredContentWidth) {
|
|
85
|
-
return Math.max(measuredContentWidth + (int) Math.ceil(dpToPx(getContext(), FINAL_WIDTH_PADDING_DP)), 1);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
79
|
private int createExactSpec(Number dimension) {
|
|
89
80
|
return makeMeasureSpec(MeasureSpec.getSize(dpToPx(getContext(), dimension.get())), EXACTLY);
|
|
90
81
|
}
|
package/android/src/test/java/com/reactnativenavigation/views/TitleBarReactButtonViewTest.java
CHANGED
|
@@ -32,8 +32,16 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
32
32
|
private static final int CHILD_WIDTH = 24;
|
|
33
33
|
private static final int CHILD_HEIGHT = 16;
|
|
34
34
|
|
|
35
|
+
// Without explicit dimensions the button measures the hosted React surface ONCE:
|
|
36
|
+
// - width AT_MOST → the surface sizes itself to its content (max-of-children under Fabric).
|
|
37
|
+
// - height AT_MOST → the surface sizes to its content height; the view is then centered
|
|
38
|
+
// vertically in the bar by the toolbar's action-view layout + the CENTER_VERTICAL gravity from
|
|
39
|
+
// onViewAdded(). A forced EXACTLY full-bar height would pin content-hugging buttons (plain
|
|
40
|
+
// text, a fixed-size avatar) to the top.
|
|
41
|
+
// It deliberately does not push a forced EXACTLY *width*; under the New Architecture that re-pushes
|
|
42
|
+
// a (initially collapsed) width to the async Fabric layout and the button never recovers.
|
|
35
43
|
@Test
|
|
36
|
-
public void
|
|
44
|
+
public void missingDimensionsSizeToContent() {
|
|
37
45
|
Activity activity = newActivity();
|
|
38
46
|
TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
|
|
39
47
|
RecordingContentView child = new RecordingContentView(activity);
|
|
@@ -41,17 +49,13 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
41
49
|
|
|
42
50
|
uut.measure(makeMeasureSpec(PARENT_WIDTH, AT_MOST), makeMeasureSpec(PARENT_HEIGHT, AT_MOST));
|
|
43
51
|
|
|
44
|
-
assertThat(uut.getMeasuredWidth()).isEqualTo(
|
|
52
|
+
assertThat(uut.getMeasuredWidth()).isEqualTo(CHILD_WIDTH);
|
|
45
53
|
assertThat(uut.getMeasuredHeight()).isEqualTo(CHILD_HEIGHT);
|
|
46
|
-
assertThat(child.widthMeasureSpecs.size()).isEqualTo(
|
|
54
|
+
assertThat(child.widthMeasureSpecs.size()).isEqualTo(1);
|
|
47
55
|
assertThat(getMode(child.widthMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
48
56
|
assertThat(getSize(child.widthMeasureSpecs.get(0))).isEqualTo(PARENT_WIDTH);
|
|
49
57
|
assertThat(getMode(child.heightMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
50
58
|
assertThat(getSize(child.heightMeasureSpecs.get(0))).isEqualTo(PARENT_HEIGHT);
|
|
51
|
-
assertThat(getMode(child.widthMeasureSpecs.get(1))).isEqualTo(EXACTLY);
|
|
52
|
-
assertThat(getSize(child.widthMeasureSpecs.get(1))).isEqualTo(finalWidth(activity));
|
|
53
|
-
assertThat(getMode(child.heightMeasureSpecs.get(1))).isEqualTo(EXACTLY);
|
|
54
|
-
assertThat(getSize(child.heightMeasureSpecs.get(1))).isEqualTo(CHILD_HEIGHT);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
@Test
|
|
@@ -76,7 +80,7 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
@Test
|
|
79
|
-
public void
|
|
83
|
+
public void zeroParentSpecsFallBackToScreenWidthAndBoundedActionBarHeight() {
|
|
80
84
|
Activity activity = newActivity();
|
|
81
85
|
TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
|
|
82
86
|
RecordingContentView child = new RecordingContentView(activity);
|
|
@@ -84,20 +88,16 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
84
88
|
|
|
85
89
|
uut.measure(makeMeasureSpec(0, AT_MOST), makeMeasureSpec(0, AT_MOST));
|
|
86
90
|
|
|
87
|
-
assertThat(child.widthMeasureSpecs.size()).isEqualTo(
|
|
91
|
+
assertThat(child.widthMeasureSpecs.size()).isEqualTo(1);
|
|
88
92
|
assertThat(getMode(child.widthMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
89
93
|
assertThat(getSize(child.widthMeasureSpecs.get(0)))
|
|
90
94
|
.isEqualTo(Math.max(activity.getResources().getDisplayMetrics().widthPixels, 1));
|
|
91
|
-
assertThat(getMode(child.widthMeasureSpecs.get(1))).isEqualTo(EXACTLY);
|
|
92
|
-
assertThat(getSize(child.widthMeasureSpecs.get(1))).isEqualTo(finalWidth(activity));
|
|
93
95
|
assertThat(getMode(child.heightMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
94
96
|
assertThat(getSize(child.heightMeasureSpecs.get(0))).isEqualTo(Math.max(resolveActionBarSize(activity), 1));
|
|
95
|
-
assertThat(getMode(child.heightMeasureSpecs.get(1))).isEqualTo(EXACTLY);
|
|
96
|
-
assertThat(getSize(child.heightMeasureSpecs.get(1))).isEqualTo(CHILD_HEIGHT);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
@Test
|
|
100
|
-
public void
|
|
100
|
+
public void rtlMissingDimensionsUseBoundedWidthAndHeight() {
|
|
101
101
|
Activity activity = newActivity();
|
|
102
102
|
TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
|
|
103
103
|
RecordingContentView child = new RecordingContentView(activity);
|
|
@@ -106,28 +106,11 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
106
106
|
|
|
107
107
|
uut.measure(makeMeasureSpec(PARENT_WIDTH, AT_MOST), makeMeasureSpec(PARENT_HEIGHT, AT_MOST));
|
|
108
108
|
|
|
109
|
-
assertThat(child.widthMeasureSpecs.size()).isEqualTo(
|
|
109
|
+
assertThat(child.widthMeasureSpecs.size()).isEqualTo(1);
|
|
110
110
|
assertThat(getMode(child.widthMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
111
111
|
assertThat(getSize(child.widthMeasureSpecs.get(0))).isEqualTo(PARENT_WIDTH);
|
|
112
|
-
assertThat(getMode(child.
|
|
113
|
-
assertThat(getSize(child.
|
|
114
|
-
assertThat(getMode(child.heightMeasureSpecs.get(1))).isEqualTo(EXACTLY);
|
|
115
|
-
assertThat(getSize(child.heightMeasureSpecs.get(1))).isEqualTo(CHILD_HEIGHT);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@Test
|
|
119
|
-
public void contentRemainsCenteredWhenMenuCellLaysButtonOutTallerThanMeasuredHeight() {
|
|
120
|
-
Activity activity = newActivity();
|
|
121
|
-
TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
|
|
122
|
-
RecordingContentView child = new RecordingContentView(activity);
|
|
123
|
-
setContentView(uut, child);
|
|
124
|
-
|
|
125
|
-
uut.measure(makeMeasureSpec(PARENT_WIDTH, AT_MOST), makeMeasureSpec(PARENT_HEIGHT, AT_MOST));
|
|
126
|
-
uut.layout(0, 0, uut.getMeasuredWidth(), PARENT_HEIGHT);
|
|
127
|
-
|
|
128
|
-
assertThat(uut.getMeasuredHeight()).isEqualTo(CHILD_HEIGHT);
|
|
129
|
-
assertThat(child.getTop()).isEqualTo((PARENT_HEIGHT - CHILD_HEIGHT) / 2);
|
|
130
|
-
assertThat(child.getBottom()).isEqualTo((PARENT_HEIGHT + CHILD_HEIGHT) / 2);
|
|
112
|
+
assertThat(getMode(child.heightMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
113
|
+
assertThat(getSize(child.heightMeasureSpecs.get(0))).isEqualTo(PARENT_HEIGHT);
|
|
131
114
|
}
|
|
132
115
|
|
|
133
116
|
@Test
|
|
@@ -170,10 +153,6 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
170
153
|
return UiUtils.dpToPx(activity, 48);
|
|
171
154
|
}
|
|
172
155
|
|
|
173
|
-
private int finalWidth(Activity activity) {
|
|
174
|
-
return CHILD_WIDTH + (int) Math.ceil(UiUtils.dpToPx(activity, 1f));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
156
|
private static class RecordingContentView extends View {
|
|
178
157
|
final List<Integer> widthMeasureSpecs = new ArrayList<>();
|
|
179
158
|
final List<Integer> heightMeasureSpecs = new ArrayList<>();
|