Skip to content

Commit 684c8a0

Browse files
Clang format ios
1 parent b34d11d commit 684c8a0

13 files changed

+205
-105
lines changed

.clang-format

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
AccessModifierOffset: -1
3+
AlignAfterOpenBracket: AlwaysBreak
4+
AlignConsecutiveAssignments: false
5+
AlignConsecutiveDeclarations: false
6+
AlignEscapedNewlinesLeft: true
7+
AlignOperands: false
8+
AlignTrailingComments: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: Empty
13+
AllowShortIfStatementsOnASingleLine: false
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: None
16+
AlwaysBreakBeforeMultilineStrings: true
17+
AlwaysBreakTemplateDeclarations: true
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BraceWrapping:
21+
AfterClass: false
22+
AfterControlStatement: false
23+
AfterEnum: false
24+
AfterFunction: false
25+
AfterNamespace: false
26+
AfterObjCDeclaration: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
BeforeCatch: false
30+
BeforeElse: false
31+
IndentBraces: false
32+
BreakBeforeBinaryOperators: None
33+
BreakBeforeBraces: Attach
34+
BreakBeforeTernaryOperators: true
35+
BreakConstructorInitializersBeforeComma: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakStringLiterals: false
38+
ColumnLimit: 80
39+
CommentPragmas: '^ IWYU pragma:'
40+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
41+
ConstructorInitializerIndentWidth: 4
42+
ContinuationIndentWidth: 4
43+
Cpp11BracedListStyle: true
44+
DerivePointerAlignment: false
45+
DisableFormat: false
46+
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
47+
IncludeCategories:
48+
- Regex: '^<.*\.h(pp)?>'
49+
Priority: 1
50+
- Regex: '^<.*'
51+
Priority: 2
52+
- Regex: '.*'
53+
Priority: 3
54+
IndentCaseLabels: true
55+
IndentWidth: 2
56+
IndentWrappedFunctionNames: false
57+
KeepEmptyLinesAtTheStartOfBlocks: false
58+
MacroBlockBegin: ''
59+
MacroBlockEnd: ''
60+
MaxEmptyLinesToKeep: 1
61+
NamespaceIndentation: None
62+
ObjCBlockIndentWidth: 2
63+
ObjCSpaceAfterProperty: true
64+
ObjCSpaceBeforeProtocolList: true
65+
PenaltyBreakBeforeFirstCallParameter: 1
66+
PenaltyBreakComment: 300
67+
PenaltyBreakFirstLessLess: 120
68+
PenaltyBreakString: 1000
69+
PenaltyExcessCharacter: 1000000
70+
PenaltyReturnTypeOnItsOwnLine: 200
71+
PointerAlignment: Right
72+
ReflowComments: true
73+
SortIncludes: true
74+
SpaceAfterCStyleCast: false
75+
SpaceBeforeAssignmentOperators: true
76+
SpaceBeforeParens: ControlStatements
77+
SpaceInEmptyParentheses: false
78+
SpacesBeforeTrailingComments: 1
79+
SpacesInAngles: false
80+
SpacesInContainerLiterals: true
81+
SpacesInCStyleCastParentheses: false
82+
SpacesInParentheses: false
83+
SpacesInSquareBrackets: false
84+
Standard: Cpp11
85+
TabWidth: 8
86+
UseTab: Never
87+
---
88+
Language: ObjC
89+
ColumnLimit: 120
90+
BreakBeforeBraces: WebKit
91+
...

ios/SafeAreaView/RCTView+SafeAreaCompat.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#import <UIKit/UIKit.h>
21
#import <React/RCTDefines.h>
32
#import <React/RCTView.h>
3+
#import <UIKit/UIKit.h>
44

5-
RCT_EXTERN BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold);
5+
RCT_EXTERN BOOL
6+
UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold);
67

78
NS_ASSUME_NONNULL_BEGIN
89

9-
@interface UIView(SafeAreaCompat)
10+
@interface UIView (SafeAreaCompat)
1011

1112
- (BOOL)nativeSafeAreaSupport;
1213
- (UIEdgeInsets)safeAreaInsetsOrEmulate;

ios/SafeAreaView/RCTView+SafeAreaCompat.m

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold)
66
{
7-
return ABS(insets1.left - insets2.left) <= threshold &&
8-
ABS(insets1.right - insets2.right) <= threshold &&
9-
ABS(insets1.top - insets2.top) <= threshold &&
10-
ABS(insets1.bottom - insets2.bottom) <= threshold;
7+
return ABS(insets1.left - insets2.left) <= threshold && ABS(insets1.right - insets2.right) <= threshold &&
8+
ABS(insets1.top - insets2.top) <= threshold && ABS(insets1.bottom - insets2.bottom) <= threshold;
119
}
1210

13-
@implementation UIView(SafeAreaCompat)
11+
@implementation UIView (SafeAreaCompat)
1412

1513
- (BOOL)nativeSafeAreaSupport
1614
{
@@ -19,19 +17,19 @@ - (BOOL)nativeSafeAreaSupport
1917

2018
- (UIEdgeInsets)safeAreaInsetsOrEmulate
2119
{
22-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
20+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
2321
if (self.nativeSafeAreaSupport) {
2422
if (@available(iOS 11.0, *)) {
2523
return self.safeAreaInsets;
2624
}
2725
}
28-
#endif
26+
#endif
2927
return self.emulatedSafeAreaInsets;
3028
}
3129

3230
- (UIEdgeInsets)emulatedSafeAreaInsets
3331
{
34-
UIViewController* vc = self.reactViewController;
32+
UIViewController *vc = self.reactViewController;
3533

3634
if (!vc) {
3735
return UIEdgeInsetsZero;

ios/SafeAreaView/RNCSafeAreaProvider.m

+14-17
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#import <React/RCTUIManager.h>
55
#import "RCTView+SafeAreaCompat.h"
66

7-
@implementation RNCSafeAreaProvider
8-
{
7+
@implementation RNCSafeAreaProvider {
98
UIEdgeInsets _currentSafeAreaInsets;
109
CGRect _currentFrame;
1110
BOOL _initialInsetsSent;
@@ -27,11 +26,9 @@ - (void)invalidateSafeAreaInsets
2726
UIEdgeInsets safeAreaInsets = [self safeAreaInsetsOrEmulate];
2827
CGRect frame = [self convertRect:self.bounds toView:nil];
2928

30-
if (
31-
_initialInsetsSent &&
32-
UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) &&
33-
CGRectEqualToRect(frame, _currentFrame)
34-
) {
29+
if (_initialInsetsSent &&
30+
UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale()) &&
31+
CGRectEqualToRect(frame, _currentFrame)) {
3532
return;
3633
}
3734

@@ -40,17 +37,17 @@ - (void)invalidateSafeAreaInsets
4037
_currentFrame = frame;
4138

4239
self.onInsetsChange(@{
43-
@"insets": @{
44-
@"top": @(safeAreaInsets.top),
45-
@"right": @(safeAreaInsets.right),
46-
@"bottom": @(safeAreaInsets.bottom),
47-
@"left": @(safeAreaInsets.left),
40+
@"insets" : @{
41+
@"top" : @(safeAreaInsets.top),
42+
@"right" : @(safeAreaInsets.right),
43+
@"bottom" : @(safeAreaInsets.bottom),
44+
@"left" : @(safeAreaInsets.left),
4845
},
49-
@"frame": @{
50-
@"x": @(frame.origin.x),
51-
@"y": @(frame.origin.y),
52-
@"width": @(frame.size.width),
53-
@"height": @(frame.size.height),
46+
@"frame" : @{
47+
@"x" : @(frame.origin.x),
48+
@"y" : @(frame.origin.y),
49+
@"width" : @(frame.size.width),
50+
@"height" : @(frame.size.height),
5451
},
5552
});
5653
}

ios/SafeAreaView/RNCSafeAreaProviderManager.m

+25-24
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,42 @@ - (UIView *)view
2020

2121
- (NSDictionary *)constantsToExport
2222
{
23-
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
23+
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
2424
if (@available(iOS 11.0, *)) {
2525
UIEdgeInsets safeAreaInsets = window.safeAreaInsets;
2626
return @{
27-
@"initialWindowMetrics": @{
28-
@"insets": @{
29-
@"top": @(safeAreaInsets.top),
30-
@"right": @(safeAreaInsets.right),
31-
@"bottom": @(safeAreaInsets.bottom),
32-
@"left": @(safeAreaInsets.left),
27+
@"initialWindowMetrics" : @{
28+
@"insets" : @{
29+
@"top" : @(safeAreaInsets.top),
30+
@"right" : @(safeAreaInsets.right),
31+
@"bottom" : @(safeAreaInsets.bottom),
32+
@"left" : @(safeAreaInsets.left),
3333
},
34-
@"frame": @{
35-
@"x": @(window.frame.origin.x),
36-
@"y": @(window.frame.origin.y),
37-
@"width": @(window.frame.size.width),
38-
@"height": @(window.frame.size.height),
34+
@"frame" : @{
35+
@"x" : @(window.frame.origin.x),
36+
@"y" : @(window.frame.origin.y),
37+
@"width" : @(window.frame.size.width),
38+
@"height" : @(window.frame.size.height),
3939
},
4040
}
4141
};
4242
} else {
43-
return @{ @"initialWindowMetrics": @{
44-
@"insets": @{
45-
@"top": @(20),
46-
@"right": @(0),
47-
@"bottom": @(0),
48-
@"left": @(0),
43+
return @{
44+
@"initialWindowMetrics" : @{
45+
@"insets" : @{
46+
@"top" : @(20),
47+
@"right" : @(0),
48+
@"bottom" : @(0),
49+
@"left" : @(0),
4950
},
50-
@"frame": @{
51-
@"x": @(window.frame.origin.x),
52-
@"y": @(window.frame.origin.y),
53-
@"width": @(window.frame.size.width),
54-
@"height": @(window.frame.size.height),
51+
@"frame" : @{
52+
@"x" : @(window.frame.origin.x),
53+
@"y" : @(window.frame.origin.y),
54+
@"width" : @(window.frame.size.width),
55+
@"height" : @(window.frame.size.height),
5556
},
5657
}
57-
} ;
58+
};
5859
}
5960
}
6061

ios/SafeAreaView/RNCSafeAreaShadowView.m

+27-23
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#import <React/RCTAssert.h>
44
#include <math.h>
55

6+
#import "RNCSafeAreaViewEdges.h"
67
#import "RNCSafeAreaViewLocalData.h"
78
#import "RNCSafeAreaViewMode.h"
8-
#import "RNCSafeAreaViewEdges.h"
99

1010
// From RCTShadowView.m
1111
typedef NS_ENUM(unsigned int, meta_prop_t) {
@@ -39,7 +39,11 @@ - (instancetype)init
3939
return self;
4040
}
4141

42-
- (void)extractEdges:(YGValue[])_metaProps top:(CGFloat *)top right:(CGFloat *)right bottom:(CGFloat *)bottom left:(CGFloat *)left
42+
- (void)extractEdges:(YGValue[])_metaProps
43+
top:(CGFloat *)top
44+
right:(CGFloat *)right
45+
bottom:(CGFloat *)bottom
46+
left:(CGFloat *)left
4347
{
4448
if (_metaProps[META_PROP_ALL].unit == YGUnitPoint) {
4549
*top = _metaProps[META_PROP_ALL].value;
@@ -61,7 +65,7 @@ - (void)extractEdges:(YGValue[])_metaProps top:(CGFloat *)top right:(CGFloat *)r
6165
if (_metaProps[META_PROP_TOP].unit == YGUnitPoint) {
6266
*top = _metaProps[META_PROP_TOP].value;
6367
}
64-
68+
6569
if (_metaProps[META_PROP_RIGHT].unit == YGUnitPoint) {
6670
*right = _metaProps[META_PROP_RIGHT].value;
6771
}
@@ -75,7 +79,8 @@ - (void)extractEdges:(YGValue[])_metaProps top:(CGFloat *)top right:(CGFloat *)r
7579
}
7680
}
7781

78-
- (void)resetInsetsForMode:(RNCSafeAreaViewMode)mode {
82+
- (void)resetInsetsForMode:(RNCSafeAreaViewMode)mode
83+
{
7984
if (mode == RNCSafeAreaViewModePadding) {
8085
super.paddingTop = _paddingMetaProps[META_PROP_TOP];
8186
super.paddingRight = _paddingMetaProps[META_PROP_RIGHT];
@@ -136,38 +141,37 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps
136141
- (void)setLocalData:(RNCSafeAreaViewLocalData *)localData
137142
{
138143
RCTAssert(
139-
[localData isKindOfClass:[RNCSafeAreaViewLocalData class]],
140-
@"Local data object for `RCTRNCSafeAreaShadowView` must be `RCTRNCSafeAreaViewLocalData` instance."
141-
);
144+
[localData isKindOfClass:[RNCSafeAreaViewLocalData class]],
145+
@"Local data object for `RCTRNCSafeAreaShadowView` must be `RCTRNCSafeAreaViewLocalData` instance.");
142146

143147
if (_localData != nil && _localData.mode != localData.mode) {
144148
[self resetInsetsForMode:_localData.mode];
145149
}
146-
150+
147151
_localData = localData;
148152
_needsUpdate = false;
149153
[self updateInsets];
150-
154+
151155
if (_localData.mode == RNCSafeAreaViewModePadding) {
152-
[super didSetProps:@[@"paddingTop", @"paddingRight", @"paddingBottom", @"paddingLeft"]];
156+
[super didSetProps:@[ @"paddingTop", @"paddingRight", @"paddingBottom", @"paddingLeft" ]];
153157
} else {
154-
[super didSetProps:@[@"marginTop", @"marginRight", @"marginBottom", @"marginLeft"]];
158+
[super didSetProps:@[ @"marginTop", @"marginRight", @"marginBottom", @"marginLeft" ]];
155159
}
156160
}
157161

158162
#define SHADOW_VIEW_MARGIN_PADDING_PROP(edge, metaProp) \
159-
- (void)setPadding##edge:(YGValue)value \
160-
{ \
161-
[super setPadding##edge:value]; \
162-
_needsUpdate = true; \
163-
_paddingMetaProps[META_PROP_##metaProp] = value; \
164-
} \
165-
- (void)setMargin##edge:(YGValue)value \
166-
{ \
167-
[super setMargin##edge:value]; \
168-
_needsUpdate = true; \
169-
_marginMetaProps[META_PROP_##metaProp] = value; \
170-
}
163+
-(void)setPadding##edge : (YGValue)value \
164+
{ \
165+
[super setPadding##edge:value]; \
166+
_needsUpdate = true; \
167+
_paddingMetaProps[META_PROP_##metaProp] = value; \
168+
} \
169+
-(void)setMargin##edge : (YGValue)value \
170+
{ \
171+
[super setMargin##edge:value]; \
172+
_needsUpdate = true; \
173+
_marginMetaProps[META_PROP_##metaProp] = value; \
174+
}
171175

172176
SHADOW_VIEW_MARGIN_PADDING_PROP(, ALL);
173177
SHADOW_VIEW_MARGIN_PADDING_PROP(Vertical, VERTICAL);

ios/SafeAreaView/RNCSafeAreaView.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#import <UIKit/UIKit.h>
2-
#import <React/RCTView.h>
31
#import <React/RCTBridge.h>
2+
#import <React/RCTView.h>
3+
#import <UIKit/UIKit.h>
44

5-
#import "RNCSafeAreaViewMode.h"
65
#import "RNCSafeAreaViewEdges.h"
6+
#import "RNCSafeAreaViewMode.h"
77

88
NS_ASSUME_NONNULL_BEGIN
99

1010
@class RNCSafeAreaView;
1111

12-
@interface RNCSafeAreaView: RCTView
12+
@interface RNCSafeAreaView : RCTView
1313

1414
- (instancetype)initWithBridge:(RCTBridge *)bridge;
1515

0 commit comments

Comments
 (0)