Bläddra i källkod

Set default title options when applying screen options

Guy Carmeli 6 år sedan
förälder
incheckning
4d83501f7b

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

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

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

64
         float scale = NavigationApplication.instance.getResources().getDisplayMetrics().density;
64
         float scale = NavigationApplication.instance.getResources().getDisplayMetrics().density;
65
         return dp * scale + 0.5f;
65
         return dp * scale + 0.5f;
66
     }
66
     }
67
-
68
 }
67
 }

+ 19
- 0
playground/src/screens/OptionsScreen.js Visa fil

107
         <Button title='Show touch through overlay' testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(false)} />
107
         <Button title='Show touch through overlay' testID={testIDs.SHOW_TOUCH_THROUGH_OVERLAY_BUTTON} onPress={() => this.onClickShowOverlay(false)} />
108
         <Button title='Push Default Options Screen' testID={testIDs.PUSH_DEFAULT_OPTIONS_BUTTON} onPress={this.onClickPushDefaultOptionsScreen} />
108
         <Button title='Push Default Options Screen' testID={testIDs.PUSH_DEFAULT_OPTIONS_BUTTON} onPress={this.onClickPushDefaultOptionsScreen} />
109
         <Button title='Show TopBar react view' testID={testIDs.SHOW_TOPBAR_REACT_VIEW} onPress={this.onShowTopBarReactView} />
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
         <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
111
         <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
111
       </View>
112
       </View>
112
     );
113
     );
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
 const styles = {
290
 const styles = {