Browse Source

Added Styler

Ran Greenberg 8 years ago
parent
commit
f683b19c4b
3 changed files with 214 additions and 15 deletions
  1. 35
    0
      ios/RNNStyler.h
  2. 150
    0
      ios/RNNStyler.m
  3. 29
    15
      ios/ReactNativeNavigation.xcodeproj/project.pbxproj

+ 35
- 0
ios/RNNStyler.h View File

@@ -0,0 +1,35 @@
1
+#import <Foundation/Foundation.h>
2
+#import <UIKit/UIKit.h>
3
+
4
+#define STYLE_TAB_BAR_HIDDEN                                    @"tabBarHidden"
5
+#define STYLE_STATUS_BAR_HIDE_WITH_NAV_BAR                      @"statusBarHideWithNavBar"
6
+#define STYLE_STATUS_BAR_HIDDEN                                 @"statusBarHidden"
7
+#define STYLE_SCREEN_BACKGROUD_COLOR                            @"screenBackgroundColor"
8
+#define STYLE_NAV_BAR_BACKGROUND_COLOR                          @"navBarBackgroundColor"
9
+#define STYLE_NAV_BAR_TEXT_COLOR                                @"navBarTextColor"
10
+#define STYLE_NAV_BAR_BOTTON_COLOR                              @"navBarButtonColor"
11
+#define STYLE_STATUS_BAR_TEXT_COLOR_SCHEME                      @"statusBarTextColorScheme"
12
+#define STYLE_STATUS_BAR_COLOR_SCHEME_LIGHT                     @"light"
13
+#define STYLE_NAV_BAR_HIDDEN                                    @"navBarHidden"
14
+#define STYLE_NAV_BAR_HIDE_ON_SCROLL                            @"navBarHideOnScroll"
15
+#define STYLE_DRAW_UNDER_NAV_BAR                                @"drawUnderNavBar"
16
+#define STYLE_DRAW_UNDER_TAB_BAR                                @"drawUnderTabBar"
17
+#define STYLE_NAV_BAR_TRANSLUCENT                               @"navBarTranslucent"
18
+#define STYLE_NAV_BAR_BLUR                                      @"navBarBlur"
19
+//#define STYLE_                      @""
20
+//#define STYLE_                      @""
21
+
22
+
23
+@interface RNNStyler : NSObject
24
+
25
+@property (nonatomic, readonly) BOOL _hidesBottomBarWhenPushed;
26
+@property (nonatomic, readonly) BOOL _statusBarHideWithNavBar;
27
+@property (nonatomic, readonly) BOOL _statusBarHidden;
28
+@property (nonatomic, readonly) BOOL _statusBarTextColorSchemeLight;
29
+@property (nonatomic, readonly) BOOL _navBarHairlineImageView;
30
+
31
+
32
+-(void)setStyleOnInit:(UIViewController*)viewController styleParams:(NSDictionary*)styleParams;
33
+-(void)setStyleOnAppear:(UIViewController*)vc styleParams:(NSDictionary*)styleParams;
34
+
35
+@end

+ 150
- 0
ios/RNNStyler.m View File

@@ -0,0 +1,150 @@
1
+//
2
+//  RNNStyler.m
3
+//  ReactNativeNavigation
4
+//
5
+//  Created by Ran Greenberg on 24/12/2016.
6
+//  Copyright © 2016 artal. All rights reserved.
7
+//
8
+
9
+#import "RNNStyler.h"
10
+#import "RCTConvert.h"
11
+
12
+@interface RNNStyler()
13
+
14
+@property (nonatomic, readwrite) BOOL _hidesBottomBarWhenPushed;
15
+@property (nonatomic, readwrite) BOOL _statusBarHideWithNavBar;
16
+@property (nonatomic, readwrite) BOOL _statusBarHidden;
17
+@property (nonatomic, readwrite) BOOL _statusBarTextColorSchemeLight;
18
+
19
+
20
+@end
21
+
22
+@implementation RNNStyler
23
+
24
+
25
+#pragma mark - API Methods
26
+
27
+
28
+-(void)setStyleOnInit:(UIViewController*)viewController styleParams:(NSDictionary*)styleParams {
29
+    NSNumber *tabBarHidden = styleParams[STYLE_TAB_BAR_HIDDEN];
30
+    self._hidesBottomBarWhenPushed = tabBarHidden ? [tabBarHidden boolValue] : NO;
31
+    
32
+    NSNumber *statusBarHideWithNavBar = styleParams[STYLE_STATUS_BAR_HIDE_WITH_NAV_BAR];
33
+    self._statusBarHideWithNavBar = statusBarHideWithNavBar ? [statusBarHideWithNavBar boolValue] : NO;
34
+    
35
+    NSNumber *statusBarHidden = styleParams[STYLE_STATUS_BAR_HIDDEN];
36
+    self._statusBarHidden = statusBarHidden ? [statusBarHidden boolValue] : NO;
37
+}
38
+
39
+
40
+-(void)setStyleOnAppear:(UIViewController*)vc styleParams:(NSDictionary*)styleParams {
41
+    
42
+    [self setNavBarStyle:vc styleParams:styleParams];
43
+    [self setStyleOnAppear:vc styleParams:styleParams];
44
+    
45
+    NSString *screenBackgroundColor = styleParams[STYLE_SCREEN_BACKGROUD_COLOR];
46
+    if (screenBackgroundColor) {
47
+        vc.view.backgroundColor = [RNNStyler colorForProcessedColor:screenBackgroundColor];
48
+    }
49
+    
50
+    NSString *statusBarTextColorScheme = styleParams[STYLE_STATUS_BAR_TEXT_COLOR_SCHEME];
51
+    if (statusBarTextColorScheme && [statusBarTextColorScheme isEqualToString:STYLE_STATUS_BAR_COLOR_SCHEME_LIGHT]) {
52
+        [RNNStyler navBarForVC:vc].barStyle = UIBarStyleBlack;
53
+        self._statusBarTextColorSchemeLight = YES;
54
+    }
55
+    else {
56
+        [RNNStyler navBarForVC:vc].barStyle = UIBarStyleDefault;
57
+        self._statusBarTextColorSchemeLight = NO;
58
+    }
59
+}
60
+
61
+
62
+#pragma mark - Setters
63
+
64
+
65
+-(void)setNavBarStyle:(UIViewController*)vc styleParams:(NSDictionary*)styleParams {
66
+    
67
+    NSString *navBarBackgroundColor = styleParams[STYLE_NAV_BAR_BACKGROUND_COLOR];
68
+    if (navBarBackgroundColor) {
69
+        [RNNStyler navBarForVC:vc].barTintColor = [RNNStyler colorForProcessedColor:navBarBackgroundColor];
70
+    }
71
+    else {
72
+        [RNNStyler navBarForVC:vc].barTintColor = nil;
73
+    }
74
+    
75
+    NSString *navBarTextColor = styleParams[STYLE_NAV_BAR_TEXT_COLOR];
76
+    if (navBarTextColor) {
77
+        [[RNNStyler navBarForVC:vc] setTitleTextAttributes:@{NSForegroundColorAttributeName : [RNNStyler colorForProcessedColor:navBarTextColor]}];
78
+    }
79
+    else {
80
+        [[RNNStyler navBarForVC:vc] setTitleTextAttributes:nil];
81
+    }
82
+    
83
+    NSString *navBarButtonColor = styleParams[STYLE_NAV_BAR_BOTTON_COLOR];
84
+    if (navBarButtonColor) {
85
+        [RNNStyler navBarForVC:vc].tintColor = [RNNStyler colorForProcessedColor:navBarButtonColor];
86
+    }
87
+    else {
88
+        [RNNStyler navBarForVC:vc].tintColor = nil;
89
+    }
90
+    
91
+    BOOL navBarHiddenBool = styleParams[STYLE_NAV_BAR_HIDDEN] ? [styleParams[STYLE_NAV_BAR_HIDDEN] boolValue] : NO;
92
+    if (vc.navigationController.navigationBarHidden != navBarHiddenBool) {
93
+        [vc.navigationController setNavigationBarHidden:navBarHiddenBool animated:YES];
94
+    }
95
+    
96
+    BOOL navBarHideOnScrollBool = styleParams[STYLE_NAV_BAR_HIDE_ON_SCROLL] ? [styleParams[STYLE_NAV_BAR_HIDE_ON_SCROLL] boolValue] : NO;
97
+    if (navBarHideOnScrollBool) {
98
+        vc.navigationController.hidesBarsOnSwipe = YES;
99
+    }
100
+    else {
101
+        vc.navigationController.hidesBarsOnSwipe = NO;
102
+    }
103
+    
104
+    BOOL drawUnderNavBarBool = styleParams[STYLE_DRAW_UNDER_NAV_BAR] ? [styleParams[STYLE_DRAW_UNDER_NAV_BAR] boolValue] : NO;
105
+    if (drawUnderNavBarBool) {
106
+        vc.edgesForExtendedLayout |= UIRectEdgeTop;
107
+    }
108
+    else {
109
+        vc.edgesForExtendedLayout &= ~UIRectEdgeTop;
110
+    }
111
+    
112
+    BOOL navBarBlurBool = styleParams[STYLE_NAV_BAR_BLUR] ? [styleParams[STYLE_NAV_BAR_BLUR] boolValue] : NO;
113
+    BOOL navBarTranslucentBool = styleParams[STYLE_NAV_BAR_TRANSLUCENT] ? [styleParams[STYLE_NAV_BAR_TRANSLUCENT] boolValue] : NO;
114
+    if (navBarTranslucentBool || navBarBlurBool) {
115
+        [RNNStyler navBarForVC:vc].translucent = YES;
116
+    }
117
+    else {
118
+        [RNNStyler navBarForVC:vc].translucent = NO;
119
+    }
120
+    
121
+}
122
+
123
+
124
+-(void)setTabBarStyle:(UIViewController*)vc styleParams:(NSDictionary*)styleParams {
125
+    
126
+    NSNumber *drawUnderTabBar = styleParams[STYLE_DRAW_UNDER_TAB_BAR];
127
+    BOOL drawUnderTabBarBool = drawUnderTabBar ? [drawUnderTabBar boolValue] : NO;
128
+    if (drawUnderTabBarBool) {
129
+        vc.edgesForExtendedLayout |= UIRectEdgeBottom;
130
+    }
131
+    else {
132
+        vc.edgesForExtendedLayout &= ~UIRectEdgeBottom;
133
+    }
134
+}
135
+
136
+
137
+#pragma mark - Helper Static Methods
138
+
139
+
140
++(UIColor*)colorForProcessedColor:(NSString*)processedColor {
141
+    return processedColor != (id)[NSNull null] ? [RCTConvert UIColor:processedColor] : nil;
142
+}
143
+
144
+
145
++(UINavigationBar*)navBarForVC:(UIViewController*)vc {
146
+    return vc ? vc.navigationController.navigationBar : nil;
147
+}
148
+
149
+
150
+@end

+ 29
- 15
ios/ReactNativeNavigation.xcodeproj/project.pbxproj View File

@@ -9,6 +9,7 @@
9 9
 /* Begin PBXBuildFile section */
10 10
 		2606F7DA1E0BC3FC00CC69CC /* RNNViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2606F7D91E0BC3FC00CC69CC /* RNNViewController.m */; };
11 11
 		260804DB1CE0D9D20094DBA1 /* RCCToolBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 260804DA1CE0D9D20094DBA1 /* RCCToolBar.m */; };
12
+		2636F1611E0EC9E7007ABB09 /* RNNStyler.m in Sources */ = {isa = PBXBuildFile; fileRef = 2636F1601E0EC9E7007ABB09 /* RNNStyler.m */; };
12 13
 		26AFF3F51D7EEE2400CBA211 /* RCCTitleViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */; };
13 14
 		CC84A19E1C1A0C4E00B3A6A2 /* RCCManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */; };
14 15
 		CC84A19F1C1A0C4E00B3A6A2 /* RCCManagerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1961C1A0C4E00B3A6A2 /* RCCManagerModule.m */; };
@@ -53,6 +54,8 @@
53 54
 		2606F7D91E0BC3FC00CC69CC /* RNNViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNViewController.m; sourceTree = "<group>"; };
54 55
 		260804D91CE0D9D20094DBA1 /* RCCToolBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCToolBar.h; sourceTree = "<group>"; };
55 56
 		260804DA1CE0D9D20094DBA1 /* RCCToolBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCToolBar.m; sourceTree = "<group>"; };
57
+		2636F15F1E0EC9E7007ABB09 /* RNNStyler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNStyler.h; sourceTree = "<group>"; };
58
+		2636F1601E0EC9E7007ABB09 /* RNNStyler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNStyler.m; sourceTree = "<group>"; };
56 59
 		26AFF3F31D7EEE2400CBA211 /* RCCTitleViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCTitleViewHelper.h; sourceTree = "<group>"; };
57 60
 		26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCTitleViewHelper.m; sourceTree = "<group>"; };
58 61
 		CC84A1931C1A0C4E00B3A6A2 /* RCCManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManager.h; sourceTree = "<group>"; };
@@ -129,6 +132,28 @@
129 132
 			path = RCCToolBar;
130 133
 			sourceTree = "<group>";
131 134
 		};
135
+		2636F1621E0FD618007ABB09 /* OLD */ = {
136
+			isa = PBXGroup;
137
+			children = (
138
+				CC84A1931C1A0C4E00B3A6A2 /* RCCManager.h */,
139
+				CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */,
140
+				CC84A1951C1A0C4E00B3A6A2 /* RCCManagerModule.h */,
141
+				CC84A1961C1A0C4E00B3A6A2 /* RCCManagerModule.m */,
142
+				CC84A1971C1A0C4E00B3A6A2 /* RCCNavigationController.h */,
143
+				CC84A1981C1A0C4E00B3A6A2 /* RCCNavigationController.m */,
144
+				CC84A1991C1A0C4E00B3A6A2 /* RCCTabBarController.h */,
145
+				CC84A19A1C1A0C4E00B3A6A2 /* RCCTabBarController.m */,
146
+				CC84A19B1C1A0C4E00B3A6A2 /* RCCViewController.h */,
147
+				CC84A19C1C1A0C4E00B3A6A2 /* RCCViewController.m */,
148
+				D84813171C8C5EB700051BAF /* RCCLightBox.h */,
149
+				D84813181C8C5EB700051BAF /* RCCLightBox.m */,
150
+				D800E8171CFED1DB004A187F /* RCCExternalViewControllerProtocol.h */,
151
+				D83514F41D29719A00D53758 /* RCCNotification.h */,
152
+				D83514F51D29719A00D53758 /* RCCNotification.m */,
153
+			);
154
+			name = OLD;
155
+			sourceTree = "<group>";
156
+		};
132 157
 		D85082BB1CBCF42400FDB961 /* RCCDrawerController */ = {
133 158
 			isa = PBXGroup;
134 159
 			children = (
@@ -197,26 +222,14 @@
197 222
 		D8AFADB41BEE6F3F00A4592D = {
198 223
 			isa = PBXGroup;
199 224
 			children = (
225
+				2636F1621E0FD618007ABB09 /* OLD */,
200 226
 				D8D779951D04B7180050CFEA /* Helpers */,
201 227
 				260804D51CE0D7090094DBA1 /* RCCToolBar */,
202 228
 				D85082BB1CBCF42400FDB961 /* RCCDrawerController */,
203
-				CC84A1931C1A0C4E00B3A6A2 /* RCCManager.h */,
204
-				CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */,
205
-				CC84A1951C1A0C4E00B3A6A2 /* RCCManagerModule.h */,
206
-				CC84A1961C1A0C4E00B3A6A2 /* RCCManagerModule.m */,
207
-				CC84A1971C1A0C4E00B3A6A2 /* RCCNavigationController.h */,
208
-				CC84A1981C1A0C4E00B3A6A2 /* RCCNavigationController.m */,
209
-				CC84A1991C1A0C4E00B3A6A2 /* RCCTabBarController.h */,
210
-				CC84A19A1C1A0C4E00B3A6A2 /* RCCTabBarController.m */,
211 229
 				2606F7D81E0BC3FC00CC69CC /* RNNViewController.h */,
212 230
 				2606F7D91E0BC3FC00CC69CC /* RNNViewController.m */,
213
-				CC84A19B1C1A0C4E00B3A6A2 /* RCCViewController.h */,
214
-				CC84A19C1C1A0C4E00B3A6A2 /* RCCViewController.m */,
215
-				D84813171C8C5EB700051BAF /* RCCLightBox.h */,
216
-				D84813181C8C5EB700051BAF /* RCCLightBox.m */,
217
-				D800E8171CFED1DB004A187F /* RCCExternalViewControllerProtocol.h */,
218
-				D83514F41D29719A00D53758 /* RCCNotification.h */,
219
-				D83514F51D29719A00D53758 /* RCCNotification.m */,
231
+				2636F15F1E0EC9E7007ABB09 /* RNNStyler.h */,
232
+				2636F1601E0EC9E7007ABB09 /* RNNStyler.m */,
220 233
 				D8AFADBE1BEE6F3F00A4592D /* Products */,
221 234
 			);
222 235
 			sourceTree = "<group>";
@@ -315,6 +328,7 @@
315 328
 				D85082E71CBCF54200FDB961 /* SidebarFlipboardAnimation.m in Sources */,
316 329
 				D85082E51CBCF54200FDB961 /* SidebarFacebookAnimation.m in Sources */,
317 330
 				CC84A1A21C1A0C4E00B3A6A2 /* RCCViewController.m in Sources */,
331
+				2636F1611E0EC9E7007ABB09 /* RNNStyler.m in Sources */,
318 332
 				2606F7DA1E0BC3FC00CC69CC /* RNNViewController.m in Sources */,
319 333
 				D85082E91CBCF54200FDB961 /* SidebarWunderlistAnimation.m in Sources */,
320 334
 				D85082E11CBCF54200FDB961 /* RCCDrawerHelper.m in Sources */,