Skip to content

Commit 58f1508

Browse files
authored
Merge branch 'master' into v7
2 parents c5b34a3 + c4f8eb2 commit 58f1508

File tree

19 files changed

+311
-29
lines changed

19 files changed

+311
-29
lines changed

lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackPresenter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private List<ButtonController> getOrCreateButtonControllers(@Nullable Map<String
317317

318318
private ButtonController createButtonController(ButtonOptions button) {
319319
ButtonController controller = new ButtonController(activity,
320-
new ButtonPresenter(button, iconResolver),
320+
new ButtonPresenter(activity, button, iconResolver),
321321
button,
322322
buttonCreator,
323323
onClickListener

lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.reactnativenavigation.viewcontrollers.stack.topbar.button
22

3+
import android.content.Context
34
import android.graphics.Color
45
import android.graphics.PorterDuff
56
import android.graphics.PorterDuffColorFilter
@@ -18,15 +19,15 @@ import com.reactnativenavigation.options.ButtonOptions
1819
import com.reactnativenavigation.utils.*
1920
import com.reactnativenavigation.views.stack.topbar.titlebar.TitleBar
2021

21-
open class ButtonPresenter(private val button: ButtonOptions, private val iconResolver: IconResolver) {
22+
open class ButtonPresenter(private val context: Context, private val button: ButtonOptions, private val iconResolver: IconResolver) {
2223
companion object {
2324
const val DISABLED_COLOR = Color.LTGRAY
2425
}
2526

2627
val styledText: SpannableString
2728
get() {
2829
return SpannableString(button.text.get("")).apply {
29-
setSpan(ButtonSpan(button), 0, button.text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
30+
setSpan(ButtonSpan(context, button), 0, button.text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
3031
}
3132
}
3233

lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonSpan.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package com.reactnativenavigation.viewcontrollers.stack.topbar.button
22

3+
import android.content.Context
34
import android.graphics.Color
45
import android.graphics.Paint
56
import android.graphics.Typeface
67
import android.text.TextPaint
78
import android.text.style.MetricAffectingSpan
89
import com.reactnativenavigation.options.ButtonOptions
10+
import com.reactnativenavigation.utils.UiUtils
911

10-
class ButtonSpan(private val button: ButtonOptions) : MetricAffectingSpan() {
12+
class ButtonSpan(private val context: Context, private val button: ButtonOptions) : MetricAffectingSpan() {
1113
override fun updateDrawState(drawState: TextPaint) = apply(drawState)
1214

1315
override fun updateMeasureState(paint: TextPaint) = apply(paint)
@@ -17,7 +19,7 @@ class ButtonSpan(private val button: ButtonOptions) : MetricAffectingSpan() {
1719
val fakeStyle = (paint.typeface?.style ?: 0) and (fontFamily?.style?.inv() ?: 1)
1820
if (fakeStyle and Typeface.BOLD != 0) paint.isFakeBoldText = true
1921
if (fakeStyle and Typeface.ITALIC != 0) paint.textSkewX = -0.25f
20-
if (fontSize.hasValue()) paint.textSize = fontSize.get().toFloat()
22+
if (fontSize.hasValue()) paint.textSize = UiUtils.dpToPx(context, fontSize.get().toFloat())
2123
paint.typeface = fontFamily
2224
}
2325
}

lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonPresenterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void beforeEach() {
4343
activity.setContentView(titleBar);
4444
button = createButton();
4545

46-
uut = new ButtonPresenter(button, new IconResolverFake(activity));
46+
uut = new ButtonPresenter(activity, button, new IconResolverFake(activity));
4747
buttonController = new ButtonController(
4848
activity,
4949
uut,

lib/android/app/src/test/java/com/reactnativenavigation/utils/ButtonSpanTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
package com.reactnativenavigation.utils;
22

3+
import android.app.Activity;
34
import android.graphics.Color;
45
import android.graphics.Paint;
56

67
import com.reactnativenavigation.BaseTest;
78
import com.reactnativenavigation.options.ButtonOptions;
89
import com.reactnativenavigation.options.params.Colour;
10+
import com.reactnativenavigation.options.params.Fraction;
911
import com.reactnativenavigation.viewcontrollers.stack.topbar.button.ButtonSpan;
1012

1113
import org.jetbrains.annotations.NotNull;
1214
import org.junit.Test;
15+
import org.robolectric.annotation.Config;
1316

1417
import static org.assertj.core.api.Java6Assertions.assertThat;
1518

19+
@Config(qualifiers = "xhdpi")
1620
public class ButtonSpanTest extends BaseTest {
1721
private ButtonSpan uut;
1822
private ButtonOptions button;
23+
private Activity activity;
1924

2025
@Override
2126
public void beforeEach() {
2227
button = createButton();
23-
uut = new ButtonSpan(button);
28+
activity = newActivity();
29+
uut = new ButtonSpan(activity, button);
2430
}
2531

2632
@Test
@@ -31,6 +37,15 @@ public void apply_colorIsNotHandled() {
3137
assertThat(paint.getColor()).isNotEqualTo(button.color.get());
3238
}
3339

40+
@Test
41+
public void apply_fontSizeIsAppliedInDp() {
42+
button.fontSize = new Fraction(14);
43+
Paint paint = new Paint();
44+
uut.apply(paint);
45+
46+
assertThat(paint.getTextSize()).isEqualTo(UiUtils.dpToPx(activity, 14));
47+
}
48+
3449
@NotNull
3550
private ButtonOptions createButton() {
3651
ButtonOptions button = new ButtonOptions();

lib/android/app/src/test/java/com/reactnativenavigation/utils/TitleBarHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static ButtonOptions iconButton(String id, String icon) {
4545

4646
public static ButtonController createButtonController(Activity activity, ButtonOptions button) {
4747
return new ButtonController(activity,
48-
new ButtonPresenter(button, new IconResolver(activity, ImageLoaderMock.mock())),
48+
new ButtonPresenter(activity, button, new IconResolver(activity, ImageLoaderMock.mock())),
4949
button,
5050
new TitleBarButtonCreatorMock(),
5151
buttonId -> {}

lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/TitleBarButtonControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void beforeEach() {
3030
ButtonOptions button = createComponentButton();
3131
uut = new ButtonController(
3232
activity,
33-
new ButtonPresenter(button, new IconResolver(activity, ImageLoaderMock.mock())),
33+
new ButtonPresenter(activity, button, new IconResolver(activity, ImageLoaderMock.mock())),
3434
button,
3535
new TitleBarButtonCreatorMock(),
3636
Mockito.mock(ButtonController.OnClickListener.class)

lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/TitleBarTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void setTitleFontSize_usesDpInsteadofSp() {
123123
private ButtonController createButtonController(ButtonOptions b) {
124124
return new ButtonController(
125125
activity,
126-
new ButtonPresenter(b, new IconResolverFake(activity)),
126+
new ButtonPresenter(activity, b, new IconResolverFake(activity)),
127127
b,
128128
mock(TitleBarButtonCreator.class),
129129
mock(ButtonController.OnClickListener.class)

lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/TopBarButtonControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void beforeEach() {
4747
stackController.getTopBar().layout(0, 0, 1080, 200);
4848
getTitleBar().layout(0, 0, 1080, 200);
4949

50-
optionsPresenter = spy(new ButtonPresenter(button, new IconResolverFake(activity)));
50+
optionsPresenter = spy(new ButtonPresenter(activity, button, new IconResolverFake(activity)));
5151
uut = new ButtonController(activity, optionsPresenter, button, buttonCreatorMock, (buttonId) -> {});
5252

5353
stackController.ensureViewIsCreated();

lib/src/commands/LayoutTreeCrawler.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,57 @@ describe('LayoutTreeCrawler', () => {
155155
uut.crawl(node, CommandName.SetRoot);
156156
expect(node.data.passProps).toBeUndefined();
157157
});
158+
159+
it('componentId is included in props passed to options generator', () => {
160+
let componentIdInProps: String = '';
161+
162+
when(mockedStore.getComponentClassForName('theComponentName')).thenReturn(
163+
() =>
164+
class extends React.Component {
165+
static options(props: any) {
166+
componentIdInProps = props.componentId;
167+
return {};
168+
}
169+
}
170+
);
171+
const node = {
172+
id: 'testId',
173+
type: LayoutType.Component,
174+
data: {
175+
name: 'theComponentName',
176+
passProps: { someProp: 'here' },
177+
},
178+
children: [],
179+
};
180+
uut.crawl(node, CommandName.SetRoot);
181+
expect(componentIdInProps).toEqual('testId');
182+
});
183+
184+
it('componentId does not override componentId in passProps', () => {
185+
let componentIdInProps: String = '';
186+
187+
when(mockedStore.getComponentClassForName('theComponentName')).thenReturn(
188+
() =>
189+
class extends React.Component {
190+
static options(props: any) {
191+
componentIdInProps = props.componentId;
192+
return {};
193+
}
194+
}
195+
);
196+
const node = {
197+
id: 'testId',
198+
type: LayoutType.Component,
199+
data: {
200+
name: 'theComponentName',
201+
passProps: {
202+
someProp: 'here',
203+
componentId: 'compIdFromPassProps',
204+
},
205+
},
206+
children: [],
207+
};
208+
uut.crawl(node, CommandName.SetRoot);
209+
expect(componentIdInProps).toEqual('compIdFromPassProps');
210+
});
158211
});

0 commit comments

Comments
 (0)