forked from microsoft/react-native-macos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCTUIKitCompat.h
More file actions
242 lines (189 loc) · 7.92 KB
/
RCTUIKitCompat.h
File metadata and controls
242 lines (189 loc) · 7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// [macOS]
#pragma once
#include <TargetConditionals.h>
#if !TARGET_OS_OSX
#import <UIKit/UIKit.h>
#else
#import <AppKit/AppKit.h>
#endif
NS_ASSUME_NONNULL_BEGIN
// MARK: - Color
#if !TARGET_OS_OSX
@compatibility_alias RCTPlatformColor UIColor;
@compatibility_alias RCTUIColor UIColor;
#else
@compatibility_alias RCTPlatformColor NSColor;
@compatibility_alias RCTUIColor NSColor;
@interface NSColor (RCTAppearanceResolving)
/// Resolve a dynamic/semantic NSColor for a specific appearance, analogous to
/// UIColor's -resolvedColorWithTraitCollection: on iOS.
- (NSColor *)resolvedColorWithAppearance:(NSAppearance *)appearance;
@end
#endif
// MARK: - Event types
#if TARGET_OS_OSX
#define UIEvent NSEvent
#define UITouchType NSTouchType
#define UIEventButtonMask NSEventButtonMask
#define UIKeyModifierFlags NSEventModifierFlags
#endif
// MARK: - Application notifications
#if TARGET_OS_OSX
#define UIApplicationDidBecomeActiveNotification NSApplicationDidBecomeActiveNotification
#define UIApplicationDidEnterBackgroundNotification NSApplicationDidHideNotification
#define UIApplicationDidFinishLaunchingNotification NSApplicationDidFinishLaunchingNotification
#define UIApplicationWillResignActiveNotification NSApplicationWillResignActiveNotification
#define UIApplicationWillEnterForegroundNotification NSApplicationWillUnhideNotification
#endif
// MARK: - Font constants
#if TARGET_OS_OSX
#define UIFontDescriptorFamilyAttribute NSFontFamilyAttribute;
#define UIFontDescriptorNameAttribute NSFontNameAttribute;
#define UIFontDescriptorFaceAttribute NSFontFaceAttribute;
#define UIFontDescriptorSizeAttribute NSFontSizeAttribute
#define UIFontDescriptorTraitsAttribute NSFontTraitsAttribute
#define UIFontDescriptorFeatureSettingsAttribute NSFontFeatureSettingsAttribute
#define UIFontSymbolicTrait NSFontSymbolicTrait
#define UIFontWeightTrait NSFontWeightTrait
#define UIFontFeatureTypeIdentifierKey NSFontFeatureTypeIdentifierKey
#define UIFontFeatureSelectorIdentifierKey NSFontFeatureSelectorIdentifierKey
#define UIFontWeightUltraLight NSFontWeightUltraLight
#define UIFontWeightThin NSFontWeightThin
#define UIFontWeightLight NSFontWeightLight
#define UIFontWeightRegular NSFontWeightRegular
#define UIFontWeightMedium NSFontWeightMedium
#define UIFontWeightSemibold NSFontWeightSemibold
#define UIFontWeightBold NSFontWeightBold
#define UIFontWeightHeavy NSFontWeightHeavy
#define UIFontWeightBlack NSFontWeightBlack
#define UIFontDescriptorSystemDesign NSFontDescriptorSystemDesign
#define UIFontDescriptorSystemDesignDefault NSFontDescriptorSystemDesignDefault
#define UIFontDescriptorSystemDesignSerif NSFontDescriptorSystemDesignSerif
#define UIFontDescriptorSystemDesignRounded NSFontDescriptorSystemDesignRounded
#define UIFontDescriptorSystemDesignMonospaced NSFontDescriptorSystemDesignMonospaced
#endif // TARGET_OS_OSX
// MARK: - Font type compatibility
#if !TARGET_OS_OSX
UIKIT_STATIC_INLINE UIFont *UIFontWithSize(UIFont *font, CGFloat pointSize)
{
return [font fontWithSize:pointSize];
}
UIKIT_STATIC_INLINE CGFloat UIFontLineHeight(UIFont *font)
{
return font.lineHeight;
}
#else // TARGET_OS_OSX
// Both NSFont and UIFont are toll-free bridged to CTFontRef
@compatibility_alias UIFont NSFont;
@compatibility_alias UIFontDescriptor NSFontDescriptor;
typedef NSFontSymbolicTraits UIFontDescriptorSymbolicTraits;
typedef NSFontWeight UIFontWeight;
NS_INLINE NSFont *UIFontWithSize(NSFont *font, CGFloat pointSize)
{
return [NSFont fontWithDescriptor:font.fontDescriptor size:pointSize];
}
NS_INLINE CGFloat UIFontLineHeight(NSFont *font)
{
return ceilf(font.ascender + ABS(font.descender) + font.leading);
}
#endif // TARGET_OS_OSX
// MARK: - View controller
#if TARGET_OS_OSX
@compatibility_alias UIViewController NSViewController;
#endif
// MARK: - Geometry
#if TARGET_OS_OSX
#define UIEdgeInsetsZero NSEdgeInsetsZero
typedef NSEdgeInsets UIEdgeInsets;
NS_INLINE NSEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
{
return NSEdgeInsetsMake(top, left, bottom, right);
}
#endif // TARGET_OS_OSX
// MARK: - Misc constants
#if TARGET_OS_OSX
#define UIActivityIndicatorView NSProgressIndicator
#define UIViewNoIntrinsicMetric -1
#define UIUserInterfaceLayoutDirection NSUserInterfaceLayoutDirection
#endif
// MARK: - Enums
#if TARGET_OS_OSX
// UIGestureRecognizer states
enum
{
UIGestureRecognizerStatePossible = NSGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan = NSGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged = NSGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded = NSGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled = NSGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed = NSGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = NSGestureRecognizerStateRecognized,
};
// UIFontDescriptor symbolic traits
enum
{
UIFontDescriptorTraitItalic = NSFontItalicTrait,
UIFontDescriptorTraitBold = NSFontBoldTrait,
UIFontDescriptorTraitCondensed = NSFontCondensedTrait,
};
// UIView autoresizing
enum : NSUInteger
{
UIViewAutoresizingNone = NSViewNotSizable,
UIViewAutoresizingFlexibleLeftMargin = NSViewMinXMargin,
UIViewAutoresizingFlexibleWidth = NSViewWidthSizable,
UIViewAutoresizingFlexibleRightMargin = NSViewMaxXMargin,
UIViewAutoresizingFlexibleTopMargin = NSViewMinYMargin,
UIViewAutoresizingFlexibleHeight = NSViewHeightSizable,
UIViewAutoresizingFlexibleBottomMargin = NSViewMaxYMargin,
};
// UIViewContentMode
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleAspectFill = NSViewLayerContentsPlacementScaleProportionallyToFill,
UIViewContentModeScaleAspectFit = NSViewLayerContentsPlacementScaleProportionallyToFit,
UIViewContentModeScaleToFill = NSViewLayerContentsPlacementScaleAxesIndependently,
UIViewContentModeCenter = NSViewLayerContentsPlacementCenter,
UIViewContentModeTopLeft = NSViewLayerContentsPlacementTopLeft,
};
// UIUserInterfaceLayoutDirection
enum : NSInteger
{
UIUserInterfaceLayoutDirectionLeftToRight = NSUserInterfaceLayoutDirectionLeftToRight,
UIUserInterfaceLayoutDirectionRightToLeft = NSUserInterfaceLayoutDirectionRightToLeft,
};
// UIActivityIndicatorViewStyle
typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) {
UIActivityIndicatorViewStyleLarge,
UIActivityIndicatorViewStyleMedium,
};
#endif // TARGET_OS_OSX
// MARK: - Gesture recognizer
#if !TARGET_OS_OSX
@compatibility_alias RCTPlatformPanGestureRecognizer UIPanGestureRecognizer;
@compatibility_alias RCTUIPanGestureRecognizer UIPanGestureRecognizer;
#else
#define UIGestureRecognizer NSGestureRecognizer
#define UIGestureRecognizerDelegate NSGestureRecognizerDelegate
@compatibility_alias RCTPlatformPanGestureRecognizer NSPanGestureRecognizer;
@compatibility_alias RCTUIPanGestureRecognizer NSPanGestureRecognizer;
@compatibility_alias UIApplication NSApplication;
#endif
// MARK: - Cross-platform typedefs
#if !TARGET_OS_OSX
@compatibility_alias RCTPlatformApplication UIApplication;
@compatibility_alias RCTPlatformWindow UIWindow;
@compatibility_alias RCTPlatformViewController UIViewController;
@compatibility_alias RCTUIApplication UIApplication;
#else
@compatibility_alias RCTPlatformApplication NSApplication;
@compatibility_alias RCTPlatformWindow NSWindow;
@compatibility_alias RCTPlatformViewController NSViewController;
@compatibility_alias RCTUIApplication NSApplication;
#endif
NS_ASSUME_NONNULL_END