소스 검색

Fix updating button options with mergeOptions (#6219)

Updating button options with mergeOptions stopped working in 6.5.0. The regression was introduced by #6090. When updating buttons, RNN didn't take button options into account when checking if two buttons are equal, instead it checked only by button id.

closes #6205

Co-authored-by: Yogev Ben David <yogev132@gmail.com>
Guy Carmeli 4 년 전
부모
커밋
b2df65a5fb
No account linked to committer's email address

+ 4
- 4
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackPresenter.java 파일 보기

@@ -306,10 +306,10 @@ public class StackPresenter {
306 306
         return new ArrayList<>(result.values());
307 307
     }
308 308
 
309
-    private List<TitleBarButtonController> getOrCreateButtonControllersById(@Nullable Map<String, TitleBarButtonController> currentButtons,@NonNull List<Button> buttons) {
309
+    private List<TitleBarButtonController> getOrCreateButtonControllers(@Nullable Map<String, TitleBarButtonController> currentButtons, @NonNull List<Button> buttons) {
310 310
         ArrayList result = new ArrayList<TitleBarButtonController>();
311 311
         for (Button b : buttons) {
312
-            result.add(take(first(perform(currentButtons, null, Map::values), button -> button.getId().equals(b.id)), createButtonController(b)));
312
+            result.add(take(first(perform(currentButtons, null, Map::values), button -> button.getButton().equals(b)), createButtonController(b)));
313 313
         }
314 314
         return result;
315 315
     }
@@ -369,7 +369,7 @@ public class StackPresenter {
369 369
     private void mergeRightButtons(TopBarOptions options, TopBarButtons buttons, View child) {
370 370
         if (buttons.right == null) return;
371 371
         List<Button> rightButtons = mergeButtonsWithColor(buttons.right, options.rightButtonColor, options.rightButtonDisabledColor);
372
-        List<TitleBarButtonController> toMerge = getOrCreateButtonControllersById(componentRightButtons.get(child), rightButtons);
372
+        List<TitleBarButtonController> toMerge = getOrCreateButtonControllers(componentRightButtons.get(child), rightButtons);
373 373
         List<TitleBarButtonController> toRemove = difference(currentRightButtons, toMerge, TitleBarButtonController::equals);
374 374
         forEach(toRemove, TitleBarButtonController::destroy);
375 375
 
@@ -383,7 +383,7 @@ public class StackPresenter {
383 383
     private void mergeLeftButton(TopBarOptions options, TopBarButtons buttons, View child) {
384 384
         if (buttons.left == null) return;
385 385
         List<Button> leftButtons = mergeButtonsWithColor(buttons.left, options.leftButtonColor, options.leftButtonDisabledColor);
386
-        List<TitleBarButtonController> toMerge = getOrCreateButtonControllersById(componentLeftButtons.get(child), leftButtons);
386
+        List<TitleBarButtonController> toMerge = getOrCreateButtonControllers(componentLeftButtons.get(child), leftButtons);
387 387
         componentLeftButtons.put(child, keyBy(toMerge, TitleBarButtonController::getButtonInstanceId));
388 388
         topBarController.setLeftButtons(toMerge);
389 389
     }

+ 0
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TitleBarButtonController.java 파일 보기

@@ -29,7 +29,6 @@ import java.util.List;
29 29
 
30 30
 import androidx.annotation.NonNull;
31 31
 import androidx.annotation.Nullable;
32
-import androidx.annotation.RestrictTo;
33 32
 import androidx.appcompat.widget.ActionMenuView;
34 33
 import androidx.appcompat.widget.Toolbar;
35 34
 import androidx.core.view.MenuItemCompat;
@@ -48,7 +47,6 @@ public class TitleBarButtonController extends ViewController<TitleBarReactButton
48 47
     private TitleBarButtonController.OnClickListener onPressListener;
49 48
     private Drawable icon;
50 49
 
51
-    @RestrictTo(RestrictTo.Scope.TESTS)
52 50
     public Button getButton() {
53 51
         return button;
54 52
     }

+ 5
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackPresenterTest.java 파일 보기

@@ -2,6 +2,7 @@ package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4 4
 import android.content.Context;
5
+import android.graphics.Color;
5 6
 import android.graphics.Typeface;
6 7
 import android.view.Gravity;
7 8
 import android.view.View;
@@ -12,9 +13,9 @@ import com.reactnativenavigation.mocks.BackDrawable;
12 13
 import com.reactnativenavigation.mocks.ImageLoaderMock;
13 14
 import com.reactnativenavigation.mocks.Mocks;
14 15
 import com.reactnativenavigation.mocks.SimpleViewController;
16
+import com.reactnativenavigation.mocks.TitleBarButtonCreatorMock;
15 17
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
16 18
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
17
-import com.reactnativenavigation.mocks.TitleBarButtonCreatorMock;
18 19
 import com.reactnativenavigation.parse.Alignment;
19 20
 import com.reactnativenavigation.parse.Component;
20 21
 import com.reactnativenavigation.parse.Options;
@@ -244,6 +245,7 @@ public class StackPresenterTest extends BaseTest {
244 245
     @Test
245 246
     public void mergeRightButtons_buttonsAreCreatedOnlyIfNeeded() {
246 247
         Options toApply = new Options();
248
+        textBtn1.color = new Colour(Color.GREEN);
247 249
         toApply.topBar.buttons.right = new ArrayList<>(asList(textBtn1, componentBtn1));
248 250
         uut.applyChildOptions(toApply, parent, child);
249 251
 
@@ -254,6 +256,7 @@ public class StackPresenterTest extends BaseTest {
254 256
 
255 257
         Options toMerge = new Options();
256 258
         toMerge.topBar.buttons.right = new ArrayList(requireNonNull(map(toApply.topBar.buttons.right, Button::copy)));
259
+        toMerge.topBar.buttons.right.get(0).color = new Colour(Color.RED);
257 260
         toMerge.topBar.buttons.right.add(1, componentBtn2);
258 261
         uut.mergeChildOptions(toMerge, Options.EMPTY, parent, child);
259 262
 
@@ -262,7 +265,7 @@ public class StackPresenterTest extends BaseTest {
262 265
         verify(topBarController).mergeRightButtons(captor2.capture(), any());
263 266
         List<TitleBarButtonController> mergedButtons = captor2.getValue();
264 267
         assertThat(mergedButtons).hasSize(3);
265
-        assertThat(appliedButtons.get(0)).isEqualTo(mergedButtons.get(0));
268
+        assertThat(appliedButtons.get(0)).isNotEqualTo(mergedButtons.get(0));
266 269
         assertThat(appliedButtons.get(1)).isEqualTo(mergedButtons.get(2));
267 270
     }
268 271