react-native-navigation 8.8.6-snapshot.2571 → 8.8.6-snapshot.2581

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.
@@ -5,11 +5,11 @@ import android.content.Context;
5
5
  import android.util.TypedValue;
6
6
  import android.view.View;
7
7
 
8
- import com.facebook.react.ReactInstanceManager;
9
8
  import com.reactnativenavigation.options.ComponentOptions;
10
9
  import com.reactnativenavigation.options.params.Number;
11
10
  import com.reactnativenavigation.react.ReactView;
12
11
 
12
+ import static android.view.View.MeasureSpec.AT_MOST;
13
13
  import static android.view.View.MeasureSpec.EXACTLY;
14
14
  import static android.view.View.MeasureSpec.makeMeasureSpec;
15
15
  import static com.reactnativenavigation.utils.UiUtils.dpToPx;
@@ -25,28 +25,44 @@ public class TitleBarReactButtonView extends ReactView {
25
25
 
26
26
  @Override
27
27
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
28
-
29
- //This is a workaround, ReactNative throws exception when views have ids, On android MenuItems
28
+ // This is a workaround, ReactNative throws exception when views have ids, On android MenuItems
30
29
  // With ActionViews like this got an id, see #7253
31
30
  if (!this.isAttachedToWindow()) {
32
31
  this.setId(View.NO_ID);
33
32
  }
34
33
 
35
- super.onMeasure(createSpec(widthMeasureSpec, component.width), createSpec(heightMeasureSpec, component.height));
34
+ super.onMeasure(
35
+ createWidthSpec(widthMeasureSpec, component.width),
36
+ createHeightSpec(heightMeasureSpec, component.height)
37
+ );
36
38
  }
37
39
 
38
- private int createSpec(int measureSpec, Number dimension) {
40
+ private int createWidthSpec(int measureSpec, Number dimension) {
41
+ return createSpec(measureSpec, dimension, Math.max(getResources().getDisplayMetrics().widthPixels, 1));
42
+ }
43
+
44
+ private int createHeightSpec(int measureSpec, Number dimension) {
45
+ if (dimension.hasValue()) {
46
+ return createExactSpec(dimension);
47
+ }
48
+ return makeMeasureSpec(Math.max(resolveActionBarSize(), 1), EXACTLY);
49
+ }
50
+
51
+ private int createSpec(int measureSpec, Number dimension, int fallbackSize) {
39
52
  if (dimension.hasValue()) {
40
- return makeMeasureSpec(MeasureSpec.getSize(dpToPx(getContext(), dimension.get())), EXACTLY);
53
+ return createExactSpec(dimension);
41
54
  } else {
42
- // When JS doesn't pass width/height, default to the theme's actionBarSize (48dp on Material).
43
- // Yoga's intrinsic measurement of the React view collapses `paddingHorizontal` on the
44
- // trailing edge in RTL (RN/Fabric measurement quirk), so we cannot trust UNSPECIFIED here -
45
- // it produces a 0dp visible inset against the screen edge in RTL.
46
- return makeMeasureSpec(resolveActionBarSize(), EXACTLY);
55
+ // Use bounded wrap-content width to avoid RN/Yoga RTL padding issues caused by
56
+ // UNSPECIFIED, without forcing every custom button to actionBarSize width.
57
+ int availableSize = MeasureSpec.getSize(measureSpec);
58
+ return makeMeasureSpec(availableSize > 0 ? availableSize : fallbackSize, AT_MOST);
47
59
  }
48
60
  }
49
61
 
62
+ private int createExactSpec(Number dimension) {
63
+ return makeMeasureSpec(MeasureSpec.getSize(dpToPx(getContext(), dimension.get())), EXACTLY);
64
+ }
65
+
50
66
  private int resolveActionBarSize() {
51
67
  TypedValue tv = new TypedValue();
52
68
  if (getContext().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
@@ -294,6 +294,20 @@ class TitleAndButtonsContainerTest : BaseTest() {
294
294
  assertThat(uut.getTitleComponent().right).isEqualTo(UUT_WIDTH - rightBarWidth - DEFAULT_LEFT_MARGIN_PX)
295
295
  }
296
296
 
297
+ @Test
298
+ fun `Component - title width shrinks by measured right buttons only`() {
299
+ val rightButtonsWidth = 48
300
+ setup(
301
+ rightBarWidth = rightButtonsWidth,
302
+ componentWidth = UUT_WIDTH,
303
+ alignment = Alignment.Default
304
+ )
305
+
306
+ idleMainLooper()
307
+ assertThat(uut.getTitleComponent().left).isEqualTo(DEFAULT_LEFT_MARGIN_PX)
308
+ assertThat(uut.getTitleComponent().right).isEqualTo(UUT_WIDTH - rightButtonsWidth - DEFAULT_LEFT_MARGIN_PX)
309
+ }
310
+
297
311
  @Test
298
312
  fun `Component - should place title between the toolbars`() {
299
313
  val leftBarWidth = 50
@@ -475,4 +489,4 @@ class TitleAndButtonsContainerTest : BaseTest() {
475
489
  }
476
490
 
477
491
  private fun getTitleSubtitleView() = (uut.getTitleComponent() as TitleSubTitleLayout)
478
- }
492
+ }
@@ -0,0 +1,135 @@
1
+ package com.reactnativenavigation.views;
2
+
3
+ import static android.view.View.MeasureSpec.AT_MOST;
4
+ import static android.view.View.MeasureSpec.EXACTLY;
5
+ import static android.view.View.MeasureSpec.getMode;
6
+ import static android.view.View.MeasureSpec.getSize;
7
+ import static android.view.View.MeasureSpec.makeMeasureSpec;
8
+ import static org.assertj.core.api.Java6Assertions.assertThat;
9
+
10
+ import android.app.Activity;
11
+ import android.util.TypedValue;
12
+ import android.view.View;
13
+ import android.view.ViewGroup;
14
+
15
+ import com.reactnativenavigation.BaseTest;
16
+ import com.reactnativenavigation.options.ComponentOptions;
17
+ import com.reactnativenavigation.options.params.Number;
18
+ import com.reactnativenavigation.options.params.Text;
19
+ import com.reactnativenavigation.utils.UiUtils;
20
+ import com.reactnativenavigation.views.stack.topbar.titlebar.TitleBarReactButtonView;
21
+
22
+ import org.junit.Test;
23
+
24
+ public class TitleBarReactButtonViewTest extends BaseTest {
25
+ private static final int PARENT_WIDTH = 200;
26
+ private static final int PARENT_HEIGHT = 100;
27
+ private static final int CHILD_WIDTH = 24;
28
+ private static final int CHILD_HEIGHT = 16;
29
+
30
+ @Test
31
+ public void missingDimensionsMeasureToContentWithinParentBounds() {
32
+ Activity activity = newActivity();
33
+ TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
34
+ uut.addView(new FixedSizeView(activity), new ViewGroup.LayoutParams(CHILD_WIDTH, CHILD_HEIGHT));
35
+
36
+ uut.measure(makeMeasureSpec(PARENT_WIDTH, AT_MOST), makeMeasureSpec(PARENT_HEIGHT, AT_MOST));
37
+
38
+ assertThat(uut.getMeasuredWidth()).isEqualTo(CHILD_WIDTH);
39
+ assertThat(uut.getMeasuredHeight()).isEqualTo(resolveActionBarSize(activity));
40
+ }
41
+
42
+ @Test
43
+ public void explicitDimensionsMeasureExactly() {
44
+ Activity activity = newActivity();
45
+ ComponentOptions component = new ComponentOptions();
46
+ component.width = new Number(72);
47
+ component.height = new Number(32);
48
+ TitleBarReactButtonView uut = createView(activity, component);
49
+ uut.addView(new FixedSizeView(activity), new ViewGroup.LayoutParams(CHILD_WIDTH, CHILD_HEIGHT));
50
+
51
+ uut.measure(makeMeasureSpec(PARENT_WIDTH, AT_MOST), makeMeasureSpec(PARENT_HEIGHT, AT_MOST));
52
+
53
+ assertThat(uut.getMeasuredWidth()).isEqualTo(UiUtils.dpToPx(activity, 72));
54
+ assertThat(uut.getMeasuredHeight()).isEqualTo(UiUtils.dpToPx(activity, 32));
55
+ }
56
+
57
+ @Test
58
+ public void zeroParentWidthFallbacksToBoundedAtMostSpecAndHeightUsesActionBarSize() {
59
+ Activity activity = newActivity();
60
+ TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
61
+ RecordingView child = new RecordingView(activity);
62
+ uut.addView(child, new ViewGroup.LayoutParams(
63
+ ViewGroup.LayoutParams.MATCH_PARENT,
64
+ ViewGroup.LayoutParams.MATCH_PARENT
65
+ ));
66
+
67
+ uut.measure(makeMeasureSpec(0, AT_MOST), makeMeasureSpec(0, AT_MOST));
68
+
69
+ assertThat(getMode(child.lastWidthMeasureSpec)).isEqualTo(AT_MOST);
70
+ assertThat(getSize(child.lastWidthMeasureSpec))
71
+ .isEqualTo(Math.max(activity.getResources().getDisplayMetrics().widthPixels, 1));
72
+ assertThat(getMode(child.lastHeightMeasureSpec)).isEqualTo(EXACTLY);
73
+ assertThat(getSize(child.lastHeightMeasureSpec)).isEqualTo(Math.max(resolveActionBarSize(activity), 1));
74
+ }
75
+
76
+ @Test
77
+ public void rtlMissingDimensionsUseBoundedSpecs() {
78
+ Activity activity = newActivity();
79
+ TitleBarReactButtonView uut = createView(activity, new ComponentOptions());
80
+ RecordingView child = new RecordingView(activity);
81
+ uut.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
82
+ uut.addView(child, new ViewGroup.LayoutParams(
83
+ ViewGroup.LayoutParams.MATCH_PARENT,
84
+ ViewGroup.LayoutParams.MATCH_PARENT
85
+ ));
86
+
87
+ uut.measure(makeMeasureSpec(PARENT_WIDTH, AT_MOST), makeMeasureSpec(PARENT_HEIGHT, AT_MOST));
88
+
89
+ assertThat(getMode(child.lastWidthMeasureSpec)).isEqualTo(AT_MOST);
90
+ assertThat(getSize(child.lastWidthMeasureSpec)).isEqualTo(PARENT_WIDTH);
91
+ assertThat(getMode(child.lastHeightMeasureSpec)).isEqualTo(EXACTLY);
92
+ assertThat(getSize(child.lastHeightMeasureSpec)).isEqualTo(resolveActionBarSize(activity));
93
+ }
94
+
95
+ private TitleBarReactButtonView createView(Activity activity, ComponentOptions component) {
96
+ component.name = new Text("ButtonComponent");
97
+ component.componentId = new Text("ButtonComponentId");
98
+ return new TitleBarReactButtonView(activity, component);
99
+ }
100
+
101
+ private int resolveActionBarSize(Activity activity) {
102
+ TypedValue tv = new TypedValue();
103
+ if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
104
+ return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
105
+ }
106
+ return UiUtils.dpToPx(activity, 48);
107
+ }
108
+
109
+ private static class FixedSizeView extends View {
110
+ FixedSizeView(Activity activity) {
111
+ super(activity);
112
+ }
113
+
114
+ @Override
115
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
116
+ setMeasuredDimension(CHILD_WIDTH, CHILD_HEIGHT);
117
+ }
118
+ }
119
+
120
+ private static class RecordingView extends View {
121
+ int lastWidthMeasureSpec;
122
+ int lastHeightMeasureSpec;
123
+
124
+ RecordingView(Activity activity) {
125
+ super(activity);
126
+ }
127
+
128
+ @Override
129
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
130
+ lastWidthMeasureSpec = widthMeasureSpec;
131
+ lastHeightMeasureSpec = heightMeasureSpec;
132
+ setMeasuredDimension(getSize(widthMeasureSpec), getSize(heightMeasureSpec));
133
+ }
134
+ }
135
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-navigation",
3
- "version": "8.8.6-snapshot.2571",
3
+ "version": "8.8.6-snapshot.2581",
4
4
  "description": "React Native Navigation - truly native navigation for iOS and Android",
5
5
  "license": "MIT",
6
6
  "nativePackage": true,