Procházet zdrojové kódy

Set default title options when applying screen options

Guy Carmeli před 6 roky
rodič
revize
4d83501f7b

+ 6
- 2
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java Zobrazit soubor

@@ -1,6 +1,7 @@
1 1
 package com.reactnativenavigation.presentation;
2 2
 
3 3
 import android.app.Activity;
4
+import android.graphics.Color;
4 5
 import android.support.annotation.NonNull;
5 6
 
6 7
 import com.reactnativenavigation.interfaces.ChildDisappearListener;
@@ -18,6 +19,9 @@ import com.reactnativenavigation.views.topbar.TopBar;
18 19
 import java.util.ArrayList;
19 20
 
20 21
 public class OptionsPresenter {
22
+    private static final int DEFAULT_TITLE_COLOR = Color.BLACK;
23
+    private static final int DEFAULT_SUBTITLE_COLOR = Color.GRAY;
24
+
21 25
     private TopBar topBar;
22 26
 
23 27
     public OptionsPresenter(TopBar topBar) {
@@ -39,13 +43,13 @@ public class OptionsPresenter {
39 43
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component) {
40 44
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
41 45
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component.get(), options.title.alignment);
42
-        if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
43 46
         if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize.get());
47
+        topBar.setTitleTextColor(options.title.color.get(DEFAULT_TITLE_COLOR));
44 48
         topBar.setTitleTypeface(options.title.fontFamily);
45 49
 
46 50
         if (options.subtitle.text.hasValue()) topBar.setSubtitle(options.subtitle.text.get());
47
-        if (options.subtitle.color.hasValue()) topBar.setSubtitleColor(options.subtitle.color.get());
48 51
         if (options.subtitle.fontSize.hasValue()) topBar.setSubtitleFontSize(options.subtitle.fontSize.get());
52
+        topBar.setSubtitleColor(options.subtitle.color.get(DEFAULT_SUBTITLE_COLOR));
49 53
         topBar.setSubtitleFontFamily(options.subtitle.fontFamily);
50 54
 
51 55
         topBar.setBackgroundColor(options.background.color);

+ 0
- 1
lib/android/app/src/main/java/com/reactnativenavigation/utils/UiUtils.java Zobrazit soubor

@@ -64,5 +64,4 @@ public class UiUtils {
64 64
         float scale = NavigationApplication.instance.getResources().getDisplayMetrics().density;
65 65
         return dp * scale + 0.5f;
66 66
     }
67
-
68 67
 }

+ 19
- 0
playground/src/screens/OptionsScreen.js Zobrazit soubor

@@ -107,6 +107,7 @@ class OptionsScreen extends Component {
107 107
         <Button title='Show touch through overlay' testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(false)} />
108 108
         <Button title='Push Default Options Screen' testID={testIDs.PUSH_DEFAULT_OPTIONS_BUTTON} onPress={this.onClickPushDefaultOptionsScreen} />
109 109
         <Button title='Show TopBar react view' testID={testIDs.SHOW_TOPBAR_REACT_VIEW} onPress={this.onShowTopBarReactView} />
110
+        {Platform.OS === 'android' ? <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onPush} /> : null}
110 111
         <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
111 112
       </View>
112 113
     );
@@ -266,6 +267,24 @@ class OptionsScreen extends Component {
266 267
       }
267 268
     });
268 269
   }
270
+
271
+  onPush = () => {
272
+    Navigation.push(this.props.componentId, {
273
+      component: {
274
+        name: 'navigation.playground.PushedScreen',
275
+        options: {
276
+          topBar: {
277
+            title: {
278
+              text: 'pushed'
279
+            },
280
+            subtitle: {
281
+              text: 'subtitle'
282
+            }
283
+          }
284
+        }
285
+      }
286
+    });
287
+  };
269 288
 }
270 289
 
271 290
 const styles = {