react-native-navigation 8.8.7-snapshot.2601 → 8.8.8-snapshot.2616
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,21 @@ 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: EXACTLY the available bar height. Giving the surface a filled height (rather than a
|
|
54
|
+
// content-hugging AT_MOST height) lets content that centers itself (e.g. a flex container with
|
|
55
|
+
// justifyContent: 'center') sit vertically centered in the bar, matching the legacy layout.
|
|
56
|
+
// It does not cause the width collapse — only a forced width does.
|
|
57
|
+
int widthSpec = component.width.hasValue()
|
|
49
58
|
? createExactSpec(component.width)
|
|
50
59
|
: 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));
|
|
60
|
+
int heightSpec = createHeightSpec(heightMeasureSpec, component.height);
|
|
61
|
+
super.onMeasure(widthSpec, heightSpec);
|
|
69
62
|
}
|
|
70
63
|
|
|
71
64
|
private int createHeightSpec(int measureSpec, Number dimension) {
|
|
@@ -73,7 +66,7 @@ public class TitleBarReactButtonView extends ReactView {
|
|
|
73
66
|
return createExactSpec(dimension);
|
|
74
67
|
}
|
|
75
68
|
int availableSize = MeasureSpec.getSize(measureSpec);
|
|
76
|
-
return makeMeasureSpec(availableSize > 0 ? availableSize : Math.max(resolveActionBarSize(), 1),
|
|
69
|
+
return makeMeasureSpec(availableSize > 0 ? availableSize : Math.max(resolveActionBarSize(), 1), EXACTLY);
|
|
77
70
|
}
|
|
78
71
|
|
|
79
72
|
private int resolveAvailableWidth(int measureSpec) {
|
|
@@ -81,10 +74,6 @@ public class TitleBarReactButtonView extends ReactView {
|
|
|
81
74
|
return availableSize > 0 ? availableSize : Math.max(getResources().getDisplayMetrics().widthPixels, 1);
|
|
82
75
|
}
|
|
83
76
|
|
|
84
|
-
private int resolveFinalWidth(int measuredContentWidth) {
|
|
85
|
-
return Math.max(measuredContentWidth + (int) Math.ceil(dpToPx(getContext(), FINAL_WIDTH_PADDING_DP)), 1);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
77
|
private int createExactSpec(Number dimension) {
|
|
89
78
|
return makeMeasureSpec(MeasureSpec.getSize(dpToPx(getContext(), dimension.get())), EXACTLY);
|
|
90
79
|
}
|
package/android/src/test/java/com/reactnativenavigation/views/TitleBarReactButtonViewTest.java
CHANGED
|
@@ -32,8 +32,14 @@ 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 EXACTLY the available bar height → the surface gets a filled box so content that
|
|
38
|
+
// centers itself (flex justifyContent: 'center') stays vertically centered in the bar.
|
|
39
|
+
// It deliberately does not push a forced EXACTLY *width*; under the New Architecture that re-pushes
|
|
40
|
+
// a (initially collapsed) width to the async Fabric layout and the button never recovers.
|
|
35
41
|
@Test
|
|
36
|
-
public void
|
|
42
|
+
public void missingDimensionsSizeWidthToContentAndFillHeight() {
|
|
37
43
|
Activity activity = newActivity();
|
|
38
44
|
TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
|
|
39
45
|
RecordingContentView child = new RecordingContentView(activity);
|
|
@@ -41,17 +47,13 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
41
47
|
|
|
42
48
|
uut.measure(makeMeasureSpec(PARENT_WIDTH, AT_MOST), makeMeasureSpec(PARENT_HEIGHT, AT_MOST));
|
|
43
49
|
|
|
44
|
-
assertThat(uut.getMeasuredWidth()).isEqualTo(
|
|
45
|
-
assertThat(uut.getMeasuredHeight()).isEqualTo(
|
|
46
|
-
assertThat(child.widthMeasureSpecs.size()).isEqualTo(
|
|
50
|
+
assertThat(uut.getMeasuredWidth()).isEqualTo(CHILD_WIDTH);
|
|
51
|
+
assertThat(uut.getMeasuredHeight()).isEqualTo(PARENT_HEIGHT);
|
|
52
|
+
assertThat(child.widthMeasureSpecs.size()).isEqualTo(1);
|
|
47
53
|
assertThat(getMode(child.widthMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
48
54
|
assertThat(getSize(child.widthMeasureSpecs.get(0))).isEqualTo(PARENT_WIDTH);
|
|
49
|
-
assertThat(getMode(child.heightMeasureSpecs.get(0))).isEqualTo(
|
|
55
|
+
assertThat(getMode(child.heightMeasureSpecs.get(0))).isEqualTo(EXACTLY);
|
|
50
56
|
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
57
|
}
|
|
56
58
|
|
|
57
59
|
@Test
|
|
@@ -76,7 +78,7 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
@Test
|
|
79
|
-
public void
|
|
81
|
+
public void zeroParentSpecsFallBackToScreenWidthAndActionBarHeight() {
|
|
80
82
|
Activity activity = newActivity();
|
|
81
83
|
TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
|
|
82
84
|
RecordingContentView child = new RecordingContentView(activity);
|
|
@@ -84,20 +86,16 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
84
86
|
|
|
85
87
|
uut.measure(makeMeasureSpec(0, AT_MOST), makeMeasureSpec(0, AT_MOST));
|
|
86
88
|
|
|
87
|
-
assertThat(child.widthMeasureSpecs.size()).isEqualTo(
|
|
89
|
+
assertThat(child.widthMeasureSpecs.size()).isEqualTo(1);
|
|
88
90
|
assertThat(getMode(child.widthMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
89
91
|
assertThat(getSize(child.widthMeasureSpecs.get(0)))
|
|
90
92
|
.isEqualTo(Math.max(activity.getResources().getDisplayMetrics().widthPixels, 1));
|
|
91
|
-
assertThat(getMode(child.
|
|
92
|
-
assertThat(getSize(child.widthMeasureSpecs.get(1))).isEqualTo(finalWidth(activity));
|
|
93
|
-
assertThat(getMode(child.heightMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
93
|
+
assertThat(getMode(child.heightMeasureSpecs.get(0))).isEqualTo(EXACTLY);
|
|
94
94
|
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
95
|
}
|
|
98
96
|
|
|
99
97
|
@Test
|
|
100
|
-
public void
|
|
98
|
+
public void rtlMissingDimensionsUseBoundedWidthAndFilledHeight() {
|
|
101
99
|
Activity activity = newActivity();
|
|
102
100
|
TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
|
|
103
101
|
RecordingContentView child = new RecordingContentView(activity);
|
|
@@ -106,28 +104,11 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
106
104
|
|
|
107
105
|
uut.measure(makeMeasureSpec(PARENT_WIDTH, AT_MOST), makeMeasureSpec(PARENT_HEIGHT, AT_MOST));
|
|
108
106
|
|
|
109
|
-
assertThat(child.widthMeasureSpecs.size()).isEqualTo(
|
|
107
|
+
assertThat(child.widthMeasureSpecs.size()).isEqualTo(1);
|
|
110
108
|
assertThat(getMode(child.widthMeasureSpecs.get(0))).isEqualTo(AT_MOST);
|
|
111
109
|
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);
|
|
110
|
+
assertThat(getMode(child.heightMeasureSpecs.get(0))).isEqualTo(EXACTLY);
|
|
111
|
+
assertThat(getSize(child.heightMeasureSpecs.get(0))).isEqualTo(PARENT_HEIGHT);
|
|
131
112
|
}
|
|
132
113
|
|
|
133
114
|
@Test
|
|
@@ -170,10 +151,6 @@ public class TitleBarReactButtonViewTest extends BaseTest {
|
|
|
170
151
|
return UiUtils.dpToPx(activity, 48);
|
|
171
152
|
}
|
|
172
153
|
|
|
173
|
-
private int finalWidth(Activity activity) {
|
|
174
|
-
return CHILD_WIDTH + (int) Math.ceil(UiUtils.dpToPx(activity, 1f));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
154
|
private static class RecordingContentView extends View {
|
|
178
155
|
final List<Integer> widthMeasureSpecs = new ArrayList<>();
|
|
179
156
|
final List<Integer> heightMeasureSpecs = new ArrayList<>();
|
package/package.json
CHANGED