@legendapp/spark 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/native.d.cts +6 -3
- package/package.json +36 -28
- package/patches/dependencies.json +252 -0
- package/patches/expo-application@55.0.19.patch +54 -0
- package/patches/expo-blur@55.0.18.patch +130 -0
- package/patches/expo-device@55.0.21.patch +149 -0
- package/patches/expo-font@55.0.8.patch +55 -0
- package/patches/expo-glass-effect@55.0.11.patch +304 -0
- package/patches/expo-haptics@55.0.18.patch +54 -0
- package/patches/expo-image-manipulator@55.0.21.patch +312 -0
- package/patches/expo-image-picker@55.0.24.patch +327 -0
- package/patches/expo-image@55.0.11.patch +158 -0
- package/patches/expo-keep-awake@55.0.8.patch +41 -0
- package/patches/expo-localization@55.0.19.patch +32 -0
- package/patches/expo-location@55.1.15.patch +190 -0
- package/patches/expo-symbols@55.0.9.patch +286 -0
- package/patches/expo-system-ui@55.0.22.patch +61 -0
- package/patches/expo-web-browser@55.0.20.patch +13 -0
- package/patches/react-native-app-logs@0.3.1.patch +20 -0
- package/patches/react-native-blurhash@2.1.3.patch +318 -0
- package/patches/react-native-community-blur@4.4.1.patch +415 -0
- package/patches/react-native-community-datetimepicker@9.2.2.patch +320 -0
- package/patches/react-native-enriched-markdown@1.1.1.patch +141 -10
- package/patches/react-native-fast-image@10.9.9.patch +131 -0
- package/patches/react-native-graph@1.4.0.patch +157 -0
- package/patches/react-native-keyboard-controller@1.22.9.patch +16 -0
- package/patches/react-native-masked-view-masked-view@0.3.2.patch +140 -0
- package/patches/react-native-mmkv@4.3.2.patch +40 -0
- package/patches/react-native-nitro-fetch@1.9.0.patch +130 -0
- package/patches/react-native-nitro-zxing@0.3.0.patch +13 -0
- package/patches/react-native-quick-base64@3.0.1.patch +13 -0
- package/patches/react-native-quick-crypto@1.1.9.patch +31 -0
- package/patches/react-native-release-profiler@0.4.5.patch +37 -0
- package/patches/react-native-screen-corner-radius@0.2.3.patch +13 -0
- package/patches/react-native-screens@4.23.0.patch +160 -0
- package/patches/react-native-svg@15.15.3.patch +31 -0
- package/patches/react-native-unistyles@3.6.0.patch +203 -0
- package/patches/react-native-worklets-core@1.6.3.patch +13 -0
- package/patches/react-navigation-native-stack@7.21.0.patch +16 -0
- package/patches/sentry-react-native@8.32.0.patch +76 -0
- package/skills/spark/UPGRADING.md +122 -3
- package/vendor/node_modules/@legendapp/spark-ai/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-audio/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-audio/src/index.macos.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-auth-session/package.json +6 -6
- package/vendor/node_modules/@legendapp/spark-auth-session/src/index.macos.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +17 -5
- package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +4 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/create.js +8 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +45 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +15 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/examples.js +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/expo-dev-patch.cjs +3 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/expo-dev-preload.cjs +3 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +26 -7
- package/vendor/node_modules/@legendapp/spark-cli/dist/metro.cjs +3 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +20 -5
- package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +1 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +10 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +3 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +28 -10
- package/vendor/node_modules/@legendapp/spark-cli/dist/release-runner-root.js +108 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +13 -13
- package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-input-cache.js +140 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/watchman.js +12 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/windows-geometry.js +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/desktop.config.json +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +27 -25
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/desktop.config.json +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +35 -33
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +29 -27
- package/vendor/node_modules/@legendapp/spark-clipboard/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-clipboard/src/index.macos.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-codex/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-commands/package.json +7 -7
- package/vendor/node_modules/@legendapp/spark-context-menu/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +7 -2
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +64 -2
- package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-desktop-config/accessibility-state.cjs +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +12 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/autolinking.cjs +7 -6
- package/vendor/node_modules/@legendapp/spark-desktop-config/config.d.cts +1 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/fabric-lifecycle.cjs +1 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/keyboard-events.cjs +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-config/macos-host.cjs +39 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +73 -20
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +2 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +8 -6
- package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-scroll-view.cjs +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-text-alignment.cjs +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-config/rtl-text-input-alignment.cjs +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-config/text-input-accessibility.cjs +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-host/macos/AppDelegate.h +6 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/macos/Main.storyboard +684 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/macos/main.m +5 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +3 -2
- package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-desktop-links/src/index.macos.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +68 -17
- package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-documents/package.json +9 -9
- package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +14 -5
- package/vendor/node_modules/@legendapp/spark-file-system/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-file-system/src/index.ts +1 -1
- package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-html/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-markdown/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-native-menu/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-notifications/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-processes/macos/RNDesktopProcesses.mm +110 -19
- package/vendor/node_modules/@legendapp/spark-processes/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-processes/src/index.ts +17 -3
- package/vendor/node_modules/@legendapp/spark-processes/src/types.ts +6 -0
- package/vendor/node_modules/@legendapp/spark-rich-text/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-secure-storage/src/index.macos.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +6 -6
- package/vendor/node_modules/@legendapp/spark-sqlite/package.json +12 -5
- package/vendor/node_modules/@legendapp/spark-system/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-tray/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +82 -18
- package/vendor/node_modules/@legendapp/spark-ui/package.json +6 -6
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +4 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +11 -9
- package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +20 -10
- package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +15 -10
- package/vendor/node_modules/@legendapp/spark-ui/src/index.macos.tsx +1 -0
- package/vendor/node_modules/@legendapp/spark-updates/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-webview/package.json +11 -4
- package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
- package/camera.ts +0 -13
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
diff --git a/RNDateTimePicker.podspec b/RNDateTimePicker.podspec
|
|
2
|
+
index 5f53282..ebb61c9 100644
|
|
3
|
+
--- a/RNDateTimePicker.podspec
|
|
4
|
+
+++ b/RNDateTimePicker.podspec
|
|
5
|
+
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
|
|
6
|
+
s.license = package['license']
|
|
7
|
+
s.author = package['author']
|
|
8
|
+
s.homepage = package['homepage']
|
|
9
|
+
- s.platforms = { :ios => "11.0", :visionos => "1.0" }
|
|
10
|
+
+ s.platforms = { :ios => "11.0", :visionos => "1.0", :osx => "14.0" }
|
|
11
|
+
s.source = { :git => "https://github.com/react-native-community/datetimepicker", :tag => "v#{s.version}" }
|
|
12
|
+
s.source_files = "ios/**/*.{h,m,mm,cpp}"
|
|
13
|
+
s.requires_arc = true
|
|
14
|
+
diff --git a/ios/RNDateTimePicker.h b/ios/RNDateTimePicker.h
|
|
15
|
+
index 00dd45d..1308e42 100644
|
|
16
|
+
--- a/ios/RNDateTimePicker.h
|
|
17
|
+
+++ b/ios/RNDateTimePicker.h
|
|
18
|
+
@@ -1,3 +1,5 @@
|
|
19
|
+
+#include <TargetConditionals.h>
|
|
20
|
+
+#if !TARGET_OS_OSX
|
|
21
|
+
/**
|
|
22
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
23
|
+
*
|
|
24
|
+
@@ -10,3 +12,4 @@
|
|
25
|
+
@interface RNDateTimePicker : UIDatePicker
|
|
26
|
+
|
|
27
|
+
@end
|
|
28
|
+
+#endif
|
|
29
|
+
diff --git a/ios/RNDateTimePicker.m b/ios/RNDateTimePicker.m
|
|
30
|
+
index 9c73c8e..7a913f2 100644
|
|
31
|
+
--- a/ios/RNDateTimePicker.m
|
|
32
|
+
+++ b/ios/RNDateTimePicker.m
|
|
33
|
+
@@ -1,3 +1,5 @@
|
|
34
|
+
+#include <TargetConditionals.h>
|
|
35
|
+
+#if !TARGET_OS_OSX
|
|
36
|
+
/**
|
|
37
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
38
|
+
*
|
|
39
|
+
@@ -73,3 +75,4 @@ - (void)setDate:(NSDate *)date {
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@end
|
|
43
|
+
+#endif
|
|
44
|
+
diff --git a/ios/RNDateTimePickerManager.h b/ios/RNDateTimePickerManager.h
|
|
45
|
+
index a619db6..2925f0e 100644
|
|
46
|
+
--- a/ios/RNDateTimePickerManager.h
|
|
47
|
+
+++ b/ios/RNDateTimePickerManager.h
|
|
48
|
+
@@ -1,3 +1,5 @@
|
|
49
|
+
+#include <TargetConditionals.h>
|
|
50
|
+
+#if !TARGET_OS_OSX
|
|
51
|
+
/**
|
|
52
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
53
|
+
*
|
|
54
|
+
@@ -17,3 +19,4 @@
|
|
55
|
+
@interface RNDateTimePickerManager : RCTViewManager
|
|
56
|
+
|
|
57
|
+
@end
|
|
58
|
+
+#endif
|
|
59
|
+
diff --git a/ios/RNDateTimePickerManager.m b/ios/RNDateTimePickerManager.m
|
|
60
|
+
index 0a69f5c..85943c5 100644
|
|
61
|
+
--- a/ios/RNDateTimePickerManager.m
|
|
62
|
+
+++ b/ios/RNDateTimePickerManager.m
|
|
63
|
+
@@ -1,3 +1,5 @@
|
|
64
|
+
+#include <TargetConditionals.h>
|
|
65
|
+
+#if !TARGET_OS_OSX
|
|
66
|
+
/**
|
|
67
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
68
|
+
*
|
|
69
|
+
@@ -196,3 +198,4 @@ + (NSString*) datepickerStyleToString: (UIDatePickerStyle) style API_AVAILABLE(
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@end
|
|
73
|
+
+#endif
|
|
74
|
+
diff --git a/ios/RNDateTimePickerShadowView.h b/ios/RNDateTimePickerShadowView.h
|
|
75
|
+
index 0e25849..a8054d1 100644
|
|
76
|
+
--- a/ios/RNDateTimePickerShadowView.h
|
|
77
|
+
+++ b/ios/RNDateTimePickerShadowView.h
|
|
78
|
+
@@ -1,3 +1,5 @@
|
|
79
|
+
+#include <TargetConditionals.h>
|
|
80
|
+
+#if !TARGET_OS_OSX
|
|
81
|
+
#import <React/RCTShadowView.h>
|
|
82
|
+
#import <React/RCTLog.h>
|
|
83
|
+
#import "RNDateTimePicker.h"
|
|
84
|
+
@@ -13,3 +15,4 @@
|
|
85
|
+
@property (nonatomic, assign) UIDatePickerStyle displayIOS API_AVAILABLE(ios(13.4));
|
|
86
|
+
|
|
87
|
+
@end
|
|
88
|
+
+#endif
|
|
89
|
+
diff --git a/ios/RNDateTimePickerShadowView.m b/ios/RNDateTimePickerShadowView.m
|
|
90
|
+
index 4ff3362..352c0af 100644
|
|
91
|
+
--- a/ios/RNDateTimePickerShadowView.m
|
|
92
|
+
+++ b/ios/RNDateTimePickerShadowView.m
|
|
93
|
+
@@ -1,3 +1,5 @@
|
|
94
|
+
+#include <TargetConditionals.h>
|
|
95
|
+
+#if !TARGET_OS_OSX
|
|
96
|
+
#import "RNDateTimePickerShadowView.h"
|
|
97
|
+
|
|
98
|
+
@implementation RNDateTimePickerShadowView
|
|
99
|
+
@@ -79,3 +81,4 @@ static YGSize RNDateTimePickerShadowViewMeasure(YGNodeConstRef node, float width
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@end
|
|
103
|
+
+#endif
|
|
104
|
+
diff --git a/ios/fabric/RNDateTimePickerComponentView.mm b/ios/fabric/RNDateTimePickerComponentView.mm
|
|
105
|
+
index ec9d7cd..2ca07f1 100644
|
|
106
|
+
--- a/ios/fabric/RNDateTimePickerComponentView.mm
|
|
107
|
+
+++ b/ios/fabric/RNDateTimePickerComponentView.mm
|
|
108
|
+
@@ -1,3 +1,5 @@
|
|
109
|
+
+#include <TargetConditionals.h>
|
|
110
|
+
+#if !TARGET_OS_OSX
|
|
111
|
+
/**
|
|
112
|
+
* RNDateTimePickerComponentView is only be available when fabric is enabled.
|
|
113
|
+
*/
|
|
114
|
+
@@ -326,4 +328,4 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
|
|
115
|
+
{
|
|
116
|
+
return RNDateTimePickerComponentView.class;
|
|
117
|
+
}
|
|
118
|
+
-
|
|
119
|
+
+#endif
|
|
120
|
+
diff --git a/ios/fabric/RNDateTimePickerComponentViewMacOS.mm b/ios/fabric/RNDateTimePickerComponentViewMacOS.mm
|
|
121
|
+
new file mode 100644
|
|
122
|
+
index 0000000..7f8f91e
|
|
123
|
+
--- /dev/null
|
|
124
|
+
+++ b/ios/fabric/RNDateTimePickerComponentViewMacOS.mm
|
|
125
|
+
@@ -0,0 +1,179 @@
|
|
126
|
+
+/**
|
|
127
|
+
+ * macOS: the Fabric picker on AppKit's NSDatePicker. NSDatePicker has no countdown mode, wheels,
|
|
128
|
+
+ * minute interval or accent color; countdown shows a time picker and spinner a stepper field.
|
|
129
|
+
+ */
|
|
130
|
+
+#include <TargetConditionals.h>
|
|
131
|
+
+#if TARGET_OS_OSX
|
|
132
|
+
+
|
|
133
|
+
+#import "RNDateTimePickerComponentView.h"
|
|
134
|
+
+#import <React/RCTConversions.h>
|
|
135
|
+
+#import <React/RCTFabricComponentsPlugins.h>
|
|
136
|
+
+
|
|
137
|
+
+#import "cpp/react/renderer/components/RNDateTimePicker/ComponentDescriptors.h"
|
|
138
|
+
+#import <react/renderer/components/RNDateTimePickerCGen/EventEmitters.h>
|
|
139
|
+
+#import <react/renderer/components/RNDateTimePickerCGen/Props.h>
|
|
140
|
+
+#import <react/renderer/components/RNDateTimePickerCGen/RCTComponentViewHelpers.h>
|
|
141
|
+
+
|
|
142
|
+
+using namespace facebook::react;
|
|
143
|
+
+
|
|
144
|
+
+@interface RNDateTimePickerComponentView () <RCTRNDateTimePickerViewProtocol>
|
|
145
|
+
+@end
|
|
146
|
+
+
|
|
147
|
+
+@implementation RNDateTimePickerComponentView {
|
|
148
|
+
+ NSDatePicker *_picker;
|
|
149
|
+
+ RNDateTimePickerShadowNode::ConcreteState::Shared _state;
|
|
150
|
+
+ CGSize _measuredSize;
|
|
151
|
+
+}
|
|
152
|
+
+
|
|
153
|
+
+- (instancetype)initWithFrame:(CGRect)frame
|
|
154
|
+
+{
|
|
155
|
+
+ if (self = [super initWithFrame:frame]) {
|
|
156
|
+
+ static const auto defaultProps = std::make_shared<const RNDateTimePickerProps>();
|
|
157
|
+
+ _props = defaultProps;
|
|
158
|
+
+
|
|
159
|
+
+ _picker = [NSDatePicker new];
|
|
160
|
+
+ _picker.datePickerStyle = NSDatePickerStyleTextFieldAndStepper;
|
|
161
|
+
+ _picker.datePickerElements = NSDatePickerElementFlagYearMonthDay;
|
|
162
|
+
+ _picker.target = self;
|
|
163
|
+
+ _picker.action = @selector(onChange:);
|
|
164
|
+
+
|
|
165
|
+
+ self.contentView = _picker;
|
|
166
|
+
+ }
|
|
167
|
+
+ return self;
|
|
168
|
+
+}
|
|
169
|
+
+
|
|
170
|
+
+- (void)onChange:(NSDatePicker *)sender
|
|
171
|
+
+{
|
|
172
|
+
+ if (!_eventEmitter) {
|
|
173
|
+
+ return;
|
|
174
|
+
+ }
|
|
175
|
+
+ RNDateTimePickerEventEmitter::OnChange event = {
|
|
176
|
+
+ // Sending time in milliseconds
|
|
177
|
+
+ .timestamp = [sender.dateValue timeIntervalSince1970] * 1000
|
|
178
|
+
+ };
|
|
179
|
+
+ std::dynamic_pointer_cast<const RNDateTimePickerEventEmitter>(_eventEmitter)->onChange(event);
|
|
180
|
+
+}
|
|
181
|
+
+
|
|
182
|
+
+// Sizes the shadow node to the picker (see adopt in ComponentDescriptors.h).
|
|
183
|
+
+- (void)updateMeasurements
|
|
184
|
+
+{
|
|
185
|
+
+ CGSize size = _picker.fittingSize;
|
|
186
|
+
+ if (_state == nullptr || CGSizeEqualToSize(size, _measuredSize)) {
|
|
187
|
+
+ return;
|
|
188
|
+
+ }
|
|
189
|
+
+ _measuredSize = size;
|
|
190
|
+
+ _state->updateState(RNDateTimePickerState{RCTSizeFromCGSize(size)});
|
|
191
|
+
+}
|
|
192
|
+
+
|
|
193
|
+
++ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
194
|
+
+{
|
|
195
|
+
+ return concreteComponentDescriptorProvider<RNDateTimePickerComponentDescriptor>();
|
|
196
|
+
+}
|
|
197
|
+
+
|
|
198
|
+
++ (BOOL)shouldBeRecycled
|
|
199
|
+
+{
|
|
200
|
+
+ return NO;
|
|
201
|
+
+}
|
|
202
|
+
+
|
|
203
|
+
+- (void)updateState:(const State::Shared &)state oldState:(const State::Shared &)oldState
|
|
204
|
+
+{
|
|
205
|
+
+ _state = std::static_pointer_cast<const RNDateTimePickerShadowNode::ConcreteState>(state);
|
|
206
|
+
+ if (oldState == nullptr) {
|
|
207
|
+
+ _measuredSize = CGSizeZero;
|
|
208
|
+
+ [self updateMeasurements];
|
|
209
|
+
+ }
|
|
210
|
+
+}
|
|
211
|
+
+
|
|
212
|
+
+- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
213
|
+
+{
|
|
214
|
+
+ const auto &oldPickerProps = *std::static_pointer_cast<const RNDateTimePickerProps>(_props);
|
|
215
|
+
+ const auto &newPickerProps = *std::static_pointer_cast<const RNDateTimePickerProps>(props);
|
|
216
|
+
+
|
|
217
|
+
+ BOOL limitsChanged = oldPickerProps.minimumDate != newPickerProps.minimumDate || oldPickerProps.maximumDate != newPickerProps.maximumDate;
|
|
218
|
+
+ if (limitsChanged) {
|
|
219
|
+
+ NSDate *minDate = newPickerProps.minimumDate ? [NSDate dateWithTimeIntervalSince1970:newPickerProps.minimumDate / 1000.0] : nil;
|
|
220
|
+
+ NSDate *maxDate = newPickerProps.maximumDate ? [NSDate dateWithTimeIntervalSince1970:newPickerProps.maximumDate / 1000.0] : nil;
|
|
221
|
+
+ // As on iOS, min > max leaves both unset and relies on the JavaScript warning.
|
|
222
|
+
+ BOOL valid = !minDate || !maxDate || [minDate compare:maxDate] != NSOrderedDescending;
|
|
223
|
+
+ _picker.minDate = nil;
|
|
224
|
+
+ _picker.maxDate = nil;
|
|
225
|
+
+ _picker.minDate = valid ? minDate : nil;
|
|
226
|
+
+ _picker.maxDate = valid ? maxDate : nil;
|
|
227
|
+
+ }
|
|
228
|
+
+
|
|
229
|
+
+ // NSDatePicker clamps its date whenever the limits move, so set the date after them.
|
|
230
|
+
+ if (limitsChanged || oldPickerProps.date != newPickerProps.date) {
|
|
231
|
+
+ _picker.dateValue = [NSDate dateWithTimeIntervalSince1970:newPickerProps.date / 1000.0];
|
|
232
|
+
+ }
|
|
233
|
+
+
|
|
234
|
+
+ if (oldPickerProps.locale != newPickerProps.locale) {
|
|
235
|
+
+ _picker.locale = [[NSLocale alloc] initWithLocaleIdentifier:RCTNSStringFromString(newPickerProps.locale)];
|
|
236
|
+
+ }
|
|
237
|
+
+
|
|
238
|
+
+ if (oldPickerProps.mode != newPickerProps.mode) {
|
|
239
|
+
+ switch (newPickerProps.mode) {
|
|
240
|
+
+ case RNDateTimePickerMode::Time:
|
|
241
|
+
+ case RNDateTimePickerMode::Countdown:
|
|
242
|
+
+ _picker.datePickerElements = NSDatePickerElementFlagHourMinute;
|
|
243
|
+
+ break;
|
|
244
|
+
+ case RNDateTimePickerMode::Datetime:
|
|
245
|
+
+ _picker.datePickerElements = NSDatePickerElementFlagYearMonthDay | NSDatePickerElementFlagHourMinute;
|
|
246
|
+
+ break;
|
|
247
|
+
+ default:
|
|
248
|
+
+ _picker.datePickerElements = NSDatePickerElementFlagYearMonthDay;
|
|
249
|
+
+ }
|
|
250
|
+
+ }
|
|
251
|
+
+
|
|
252
|
+
+ if (oldPickerProps.displayIOS != newPickerProps.displayIOS) {
|
|
253
|
+
+ _picker.datePickerStyle = newPickerProps.displayIOS == RNDateTimePickerDisplayIOS::Inline
|
|
254
|
+
+ ? NSDatePickerStyleClockAndCalendar
|
|
255
|
+
+ : NSDatePickerStyleTextFieldAndStepper;
|
|
256
|
+
+ }
|
|
257
|
+
+
|
|
258
|
+
+ if (oldPickerProps.timeZoneOffsetInMinutes != newPickerProps.timeZoneOffsetInMinutes) {
|
|
259
|
+
+ // JS standard for time zones is minutes.
|
|
260
|
+
+ _picker.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:newPickerProps.timeZoneOffsetInMinutes * 60.0];
|
|
261
|
+
+ }
|
|
262
|
+
+
|
|
263
|
+
+ if (oldPickerProps.timeZoneName != newPickerProps.timeZoneName) {
|
|
264
|
+
+ NSString *timeZoneName = RCTNSStringFromString(newPickerProps.timeZoneName);
|
|
265
|
+
+ NSTimeZone *timeZone = timeZoneName.length ? [NSTimeZone timeZoneWithName:timeZoneName] : nil;
|
|
266
|
+
+ if (timeZoneName.length && !timeZone) {
|
|
267
|
+
+ RCTLogWarn(@"'%@' does not exist in NSTimeZone.knownTimeZoneNames. Falling back to localTimeZone=%@", timeZoneName, NSTimeZone.localTimeZone.name);
|
|
268
|
+
+ }
|
|
269
|
+
+ _picker.timeZone = timeZone ?: NSTimeZone.localTimeZone;
|
|
270
|
+
+ }
|
|
271
|
+
+
|
|
272
|
+
+ if (oldPickerProps.textColor != newPickerProps.textColor) {
|
|
273
|
+
+ _picker.textColor = RCTUIColorFromSharedColor(newPickerProps.textColor) ?: NSColor.controlTextColor;
|
|
274
|
+
+ }
|
|
275
|
+
+
|
|
276
|
+
+ if (oldPickerProps.themeVariant != newPickerProps.themeVariant) {
|
|
277
|
+
+ switch (newPickerProps.themeVariant) {
|
|
278
|
+
+ case RNDateTimePickerThemeVariant::Light:
|
|
279
|
+
+ _picker.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
|
|
280
|
+
+ break;
|
|
281
|
+
+ case RNDateTimePickerThemeVariant::Dark:
|
|
282
|
+
+ _picker.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
|
|
283
|
+
+ break;
|
|
284
|
+
+ default:
|
|
285
|
+
+ _picker.appearance = nil;
|
|
286
|
+
+ }
|
|
287
|
+
+ }
|
|
288
|
+
+
|
|
289
|
+
+ if (oldPickerProps.enabled != newPickerProps.enabled) {
|
|
290
|
+
+ _picker.enabled = newPickerProps.enabled;
|
|
291
|
+
+ }
|
|
292
|
+
+
|
|
293
|
+
+ [super updateProps:props oldProps:oldProps];
|
|
294
|
+
+ [self updateMeasurements];
|
|
295
|
+
+}
|
|
296
|
+
+
|
|
297
|
+
+@end
|
|
298
|
+
+
|
|
299
|
+
+Class<RCTComponentViewProtocol> RNDateTimePickerCls(void)
|
|
300
|
+
+{
|
|
301
|
+
+ return RNDateTimePickerComponentView.class;
|
|
302
|
+
+}
|
|
303
|
+
+
|
|
304
|
+
+#endif
|
|
305
|
+
diff --git a/src/datetimepicker.macos.js b/src/datetimepicker.macos.js
|
|
306
|
+
new file mode 100644
|
|
307
|
+
index 0000000..4290def
|
|
308
|
+
--- /dev/null
|
|
309
|
+
+++ b/src/datetimepicker.macos.js
|
|
310
|
+
@@ -0,0 +1,2 @@
|
|
311
|
+
+// macOS uses the native picker, like iOS.
|
|
312
|
+
+export { default } from './datetimepicker.ios';
|
|
313
|
+
diff --git a/src/picker.macos.js b/src/picker.macos.js
|
|
314
|
+
new file mode 100644
|
|
315
|
+
index 0000000..157ac5c
|
|
316
|
+
--- /dev/null
|
|
317
|
+
+++ b/src/picker.macos.js
|
|
318
|
+
@@ -0,0 +1,2 @@
|
|
319
|
+
+// macOS uses the native picker, like iOS.
|
|
320
|
+
+export { default } from './picker.ios';
|
|
@@ -4462,18 +4462,20 @@ index d0a9b3af..9e336c7e 100644
|
|
|
4462
4462
|
}
|
|
4463
4463
|
|
|
4464
4464
|
diff --git a/ios/segments/ENRMCodeBlockContainerView.m b/ios/segments/ENRMCodeBlockContainerView.m
|
|
4465
|
-
index
|
|
4465
|
+
index 0c022cfd5644ed59ffc492b12f79ca0b3521fdc1..bb3d7cdb81628b816914b1f43e77a29615f0ea8a 100644
|
|
4466
4466
|
--- a/ios/segments/ENRMCodeBlockContainerView.m
|
|
4467
4467
|
+++ b/ios/segments/ENRMCodeBlockContainerView.m
|
|
4468
|
-
@@ -
|
|
4468
|
+
@@ -4,7 +4,9 @@
|
|
4469
|
+
#import "MarkdownASTNode.h"
|
|
4469
4470
|
#import "PasteboardUtils.h"
|
|
4470
4471
|
#if TARGET_OS_OSX
|
|
4472
|
+
+#import "ENRMHorizontalScrollView.h"
|
|
4471
4473
|
#import "ENRMMenuAction.h"
|
|
4472
4474
|
+#import "ENRMCodeBlockLineLayout.h"
|
|
4473
4475
|
#endif
|
|
4474
4476
|
|
|
4475
4477
|
// Block segment view for fenced code blocks (see SegmentRenderer.m):
|
|
4476
|
-
@@ -67,6 +
|
|
4478
|
+
@@ -67,6 +69,7 @@ static CGFloat ENRMCodeBlockHeaderLabelLineHeight(NSFont *headerFont)
|
|
4477
4479
|
return attributed;
|
|
4478
4480
|
}
|
|
4479
4481
|
|
|
@@ -4481,7 +4483,7 @@ index 0c022cfd..667592c9 100644
|
|
|
4481
4483
|
// Per-line height applied to the code text (see ENRMApplyCodeBlockTextAttributes):
|
|
4482
4484
|
// when a code block line height is configured every line fragment is exactly that
|
|
4483
4485
|
// tall; otherwise the font's natural line height is used.
|
|
4484
|
-
@@ -95,6 +
|
|
4486
|
+
@@ -95,6 +98,8 @@ static CGFloat ENRMCodeBlockCodeHeight(NSString *code, StyleConfig *config)
|
|
4485
4487
|
return ceil(lineCount * ENRMCodeBlockPerLineHeight(config));
|
|
4486
4488
|
}
|
|
4487
4489
|
|
|
@@ -4490,7 +4492,7 @@ index 0c022cfd..667592c9 100644
|
|
|
4490
4492
|
// Used only to pick the scroll indicator style for the code pane, so the
|
|
4491
4493
|
// indicator stays visible on dark code block backgrounds without affecting
|
|
4492
4494
|
// any other scroll view.
|
|
4493
|
-
@@ -140,6 +
|
|
4495
|
+
@@ -140,6 +145,7 @@ @interface ENRMCodeBlockContentView : RCTUIView
|
|
4494
4496
|
@property (nonatomic, readonly) CGFloat usedWidth;
|
|
4495
4497
|
#if TARGET_OS_OSX
|
|
4496
4498
|
@property (nonatomic, copy, nullable) NSMenu * (^menuProvider)(void);
|
|
@@ -4498,7 +4500,7 @@ index 0c022cfd..667592c9 100644
|
|
|
4498
4500
|
#endif
|
|
4499
4501
|
@end
|
|
4500
4502
|
|
|
4501
|
-
@@ -170,6 +
|
|
4503
|
+
@@ -170,6 +176,9 @@ - (void)setAttributedCode:(nullable NSAttributedString *)attributedCode
|
|
4502
4504
|
_textContainer = nil;
|
|
4503
4505
|
return;
|
|
4504
4506
|
}
|
|
@@ -4508,7 +4510,7 @@ index 0c022cfd..667592c9 100644
|
|
|
4508
4510
|
_textStorage = [[NSTextStorage alloc] initWithAttributedString:attributedCode];
|
|
4509
4511
|
_layoutManager = [[NSLayoutManager alloc] init];
|
|
4510
4512
|
_layoutManager.usesFontLeading = NO;
|
|
4511
|
-
@@ -179,6 +
|
|
4513
|
+
@@ -179,6 +188,7 @@ - (void)setAttributedCode:(nullable NSAttributedString *)attributedCode
|
|
4512
4514
|
[_layoutManager addTextContainer:_textContainer];
|
|
4513
4515
|
[_textStorage addLayoutManager:_layoutManager];
|
|
4514
4516
|
[_layoutManager ensureLayoutForTextContainer:_textContainer];
|
|
@@ -4516,7 +4518,7 @@ index 0c022cfd..667592c9 100644
|
|
|
4516
4518
|
}
|
|
4517
4519
|
|
|
4518
4520
|
- (CGFloat)usedWidth
|
|
4519
|
-
@@ -191,6 +
|
|
4521
|
+
@@ -191,6 +201,12 @@ - (CGFloat)usedWidth
|
|
4520
4522
|
|
|
4521
4523
|
- (void)drawRect:(CGRect)rect
|
|
4522
4524
|
{
|
|
@@ -4529,7 +4531,19 @@ index 0c022cfd..667592c9 100644
|
|
|
4529
4531
|
if (!_layoutManager) {
|
|
4530
4532
|
return;
|
|
4531
4533
|
}
|
|
4532
|
-
@@ -
|
|
4534
|
+
@@ -302,7 +318,11 @@ - (instancetype)initWithConfig:(StyleConfig *)config
|
|
4535
|
+
|
|
4536
|
+
- (void)setupScrollView
|
|
4537
|
+
{
|
|
4538
|
+
+#if TARGET_OS_OSX
|
|
4539
|
+
+ _scrollView = [[ENRMHorizontalScrollView alloc] init];
|
|
4540
|
+
+#else
|
|
4541
|
+
_scrollView = [[RCTUIScrollView alloc] init];
|
|
4542
|
+
+#endif
|
|
4543
|
+
_scrollView.showsVerticalScrollIndicator = NO;
|
|
4544
|
+
_scrollView.showsHorizontalScrollIndicator = YES;
|
|
4545
|
+
_codeContentView = [[ENRMCodeBlockContentView alloc] initWithFrame:CGRectZero];
|
|
4546
|
+
@@ -409,7 +429,12 @@ - (void)rebuildAttributedCode
|
|
4533
4547
|
// Setting attributedCode builds and lays out the cached TextKit stack once;
|
|
4534
4548
|
// width then reads out of that layout, and height stays analytic.
|
|
4535
4549
|
_codeContentView.attributedCode = _attributedCode;
|
|
@@ -4542,7 +4556,7 @@ index 0c022cfd..667592c9 100644
|
|
|
4542
4556
|
}
|
|
4543
4557
|
|
|
4544
4558
|
- (void)applyCodeBlockNode:(MarkdownASTNode *)node
|
|
4545
|
-
@@ -482,8 +
|
|
4559
|
+
@@ -482,8 +507,13 @@ + (CGFloat)measureHeightForCodeBlockNode:(MarkdownASTNode *)node config:(StyleCo
|
|
4546
4560
|
{
|
|
4547
4561
|
CGFloat inset = ENRMCodeBlockContentInset(config);
|
|
4548
4562
|
CGFloat headerH = inset + ENRMCodeBlockHeaderLabelLineHeight(ENRMCodeBlockHeaderFont(config));
|
|
@@ -7749,3 +7763,120 @@ index ec26198d..58c362d3 100644
|
|
|
7749
7763
|
}
|
|
7750
7764
|
|
|
7751
7765
|
- (void)showTrailingBulletInTextView:(UITextView *)textView
|
|
7766
|
+
diff --git a/ios/segments/ENRMVideoContainerView.m b/ios/segments/ENRMVideoContainerView.m
|
|
7767
|
+
index d3137e1597d588a444ef1fa4cc85a4ac4d1ae9ab..e516922ff4455b7f0455a6c67c4791f586fabf8f 100644
|
|
7768
|
+
--- a/ios/segments/ENRMVideoContainerView.m
|
|
7769
|
+
+++ b/ios/segments/ENRMVideoContainerView.m
|
|
7770
|
+
@@ -296,8 +296,36 @@ - (void)dealloc
|
|
7771
|
+
|
|
7772
|
+
// ===== macOS implementation =====
|
|
7773
|
+
|
|
7774
|
+
+@interface ENRMPlayerView : AVPlayerView
|
|
7775
|
+
+@end
|
|
7776
|
+
+
|
|
7777
|
+
+@implementation ENRMPlayerView
|
|
7778
|
+
+
|
|
7779
|
+
+- (NSView *)hitTest:(NSPoint)point
|
|
7780
|
+
+{
|
|
7781
|
+
+ NSView *hit = [super hitTest:point];
|
|
7782
|
+
+ NSEvent *event = NSApp.currentEvent;
|
|
7783
|
+
+ // AVKit's internal content view seeks without forwarding scrollWheel:.
|
|
7784
|
+
+ if (hit && event.type == NSEventTypeScrollWheel &&
|
|
7785
|
+
+ fabs(event.scrollingDeltaY) > fabs(event.scrollingDeltaX)) {
|
|
7786
|
+
+ return self;
|
|
7787
|
+
+ }
|
|
7788
|
+
+ return hit;
|
|
7789
|
+
+}
|
|
7790
|
+
+
|
|
7791
|
+
+- (void)scrollWheel:(NSEvent *)event
|
|
7792
|
+
+{
|
|
7793
|
+
+ if (fabs(event.scrollingDeltaY) > fabs(event.scrollingDeltaX)) {
|
|
7794
|
+
+ [self.nextResponder scrollWheel:event];
|
|
7795
|
+
+ } else {
|
|
7796
|
+
+ [super scrollWheel:event];
|
|
7797
|
+
+ }
|
|
7798
|
+
+}
|
|
7799
|
+
+
|
|
7800
|
+
+@end
|
|
7801
|
+
+
|
|
7802
|
+
@implementation ENRMVideoContainerView {
|
|
7803
|
+
- AVPlayerView *_playerView;
|
|
7804
|
+
+ ENRMPlayerView *_playerView;
|
|
7805
|
+
NSString *_currentURL;
|
|
7806
|
+
}
|
|
7807
|
+
|
|
7808
|
+
@@ -308,7 +336,7 @@ - (instancetype)initWithConfig:(StyleConfig *)config
|
|
7809
|
+
_dynamicProps = [[ENRMDynamicBlockProps alloc] init];
|
|
7810
|
+
self.wantsLayer = YES;
|
|
7811
|
+
|
|
7812
|
+
- _playerView = [[AVPlayerView alloc] init];
|
|
7813
|
+
+ _playerView = [[ENRMPlayerView alloc] init];
|
|
7814
|
+
_playerView.controlsStyle = AVPlayerViewControlsStyleInline;
|
|
7815
|
+
_playerView.wantsLayer = YES;
|
|
7816
|
+
_playerView.layer.masksToBounds = YES;
|
|
7817
|
+
diff --git a/ios/segments/TableContainerView.m b/ios/segments/TableContainerView.m
|
|
7818
|
+
index 7a39908bd40067a817051d4f0a1c9e7f23e9b4eb..944b088e75a773f2a0bf825709e9a6cf6b15e1bc 100644
|
|
7819
|
+
--- a/ios/segments/TableContainerView.m
|
|
7820
|
+
+++ b/ios/segments/TableContainerView.m
|
|
7821
|
+
@@ -12,6 +12,7 @@
|
|
7822
|
+
#import "StyleConfig.h"
|
|
7823
|
+
#include <TargetConditionals.h>
|
|
7824
|
+
#if TARGET_OS_OSX
|
|
7825
|
+
+#import "ENRMHorizontalScrollView.h"
|
|
7826
|
+
#import "ENRMMenuAction.h"
|
|
7827
|
+
#import "ENRMTableGridView.h"
|
|
7828
|
+
#else
|
|
7829
|
+
@@ -270,7 +271,11 @@ - (instancetype)initWithConfig:(StyleConfig *)config
|
|
7830
|
+
|
|
7831
|
+
- (void)setupScrollView
|
|
7832
|
+
{
|
|
7833
|
+
+#if TARGET_OS_OSX
|
|
7834
|
+
+ _scrollView = [[ENRMHorizontalScrollView alloc] init];
|
|
7835
|
+
+#else
|
|
7836
|
+
_scrollView = [[RCTUIScrollView alloc] init];
|
|
7837
|
+
+#endif
|
|
7838
|
+
_scrollView.showsVerticalScrollIndicator = NO;
|
|
7839
|
+
_scrollView.showsHorizontalScrollIndicator = YES;
|
|
7840
|
+
#if !TARGET_OS_OSX
|
|
7841
|
+
diff --git a/ios/utils/ENRMHorizontalScrollView.h b/ios/utils/ENRMHorizontalScrollView.h
|
|
7842
|
+
new file mode 100644
|
|
7843
|
+
index 0000000000000000000000000000000000000000..024bb02e051a01ff9b9aaa7930445d91101d9599
|
|
7844
|
+
--- /dev/null
|
|
7845
|
+
+++ b/ios/utils/ENRMHorizontalScrollView.h
|
|
7846
|
+
@@ -0,0 +1,8 @@
|
|
7847
|
+
+#pragma once
|
|
7848
|
+
+
|
|
7849
|
+
+#import "ENRMUIKit.h"
|
|
7850
|
+
+
|
|
7851
|
+
+#if TARGET_OS_OSX
|
|
7852
|
+
+@interface ENRMHorizontalScrollView : RCTUIScrollView
|
|
7853
|
+
+@end
|
|
7854
|
+
+#endif
|
|
7855
|
+
diff --git a/ios/utils/ENRMHorizontalScrollView.m b/ios/utils/ENRMHorizontalScrollView.m
|
|
7856
|
+
new file mode 100644
|
|
7857
|
+
index 0000000000000000000000000000000000000000..73ff9a8a7cfbfb1a6958a98383bf44fc84f050f9
|
|
7858
|
+
--- /dev/null
|
|
7859
|
+
+++ b/ios/utils/ENRMHorizontalScrollView.m
|
|
7860
|
+
@@ -0,0 +1,22 @@
|
|
7861
|
+
+#import "ENRMHorizontalScrollView.h"
|
|
7862
|
+
+
|
|
7863
|
+
+#if TARGET_OS_OSX
|
|
7864
|
+
+@implementation ENRMHorizontalScrollView
|
|
7865
|
+
+
|
|
7866
|
+
+// Overriding scrollWheel: otherwise disables responsive horizontal scrolling.
|
|
7867
|
+
++ (BOOL)isCompatibleWithResponsiveScrolling
|
|
7868
|
+
+{
|
|
7869
|
+
+ return YES;
|
|
7870
|
+
+}
|
|
7871
|
+
+
|
|
7872
|
+
+- (void)scrollWheel:(NSEvent *)event
|
|
7873
|
+
+{
|
|
7874
|
+
+ if (fabs(event.scrollingDeltaY) > fabs(event.scrollingDeltaX)) {
|
|
7875
|
+
+ [self.nextResponder scrollWheel:event];
|
|
7876
|
+
+ } else {
|
|
7877
|
+
+ [super scrollWheel:event];
|
|
7878
|
+
+ }
|
|
7879
|
+
+}
|
|
7880
|
+
+
|
|
7881
|
+
+@end
|
|
7882
|
+
+#endif
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
diff --git a/src/index.macos.tsx b/src/index.macos.tsx
|
|
2
|
+
new file mode 100644
|
|
3
|
+
index 0000000..0d10daf
|
|
4
|
+
--- /dev/null
|
|
5
|
+
+++ b/src/index.macos.tsx
|
|
6
|
+
@@ -0,0 +1,125 @@
|
|
7
|
+
+// FastImage on macOS: React Native's Image stands in for the native view, which is
|
|
8
|
+
+// UIKit only. Sources (uri, headers, require()), objectFit, tintColor, placeholder and
|
|
9
|
+
+// defaultSource while loading, and the load events work; Image's own caches replace
|
|
10
|
+
+// SDWebImage's, so cache options, thumbhash/blurhash placeholders, transitions and
|
|
11
|
+
+// several sizes of one image are not supported (the largest size loads).
|
|
12
|
+
+import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react'
|
|
13
|
+
+import { Image, StyleSheet, View, type ImageResizeMode } from 'react-native'
|
|
14
|
+
+import { cacheControl, priority, resizeMode } from './constants'
|
|
15
|
+
+import { splitBackgroundProps } from './backgroundProps'
|
|
16
|
+
+import type {
|
|
17
|
+
+ ClearCacheResult,
|
|
18
|
+
+ FastImageBackgroundProps,
|
|
19
|
+
+ FastImageProps,
|
|
20
|
+
+ FastImageRef,
|
|
21
|
+
+ FastImageStaticProperties,
|
|
22
|
+
+ ObjectFit,
|
|
23
|
+
+ PreloadResult,
|
|
24
|
+
+} from './index'
|
|
25
|
+
+
|
|
26
|
+
+export type * from './index'
|
|
27
|
+
+
|
|
28
|
+
+const fits: Record<ObjectFit, ImageResizeMode> = {
|
|
29
|
+
+ fill: 'stretch',
|
|
30
|
+
+ contain: 'contain',
|
|
31
|
+
+ cover: 'cover',
|
|
32
|
+
+ none: 'center',
|
|
33
|
+
+ 'scale-down': 'center',
|
|
34
|
+
+}
|
|
35
|
+
+const unsupported = (name: string) =>
|
|
36
|
+
+ Promise.resolve({ ok: false as const, error: `FastImage.${name} is not supported on macOS` })
|
|
37
|
+
+
|
|
38
|
+
+type OneSource = Exclude<NonNullable<FastImageProps['source']>, readonly unknown[]>
|
|
39
|
+
+
|
|
40
|
+
+function imageSource(source: FastImageProps['source']) {
|
|
41
|
+
+ const sources = (Array.isArray(source) ? source : [source]) as (OneSource | undefined)[]
|
|
42
|
+
+ const area = (one: OneSource | undefined) => typeof one === 'object' ? (one.width ?? 0) * (one.height ?? 0) : 0
|
|
43
|
+
+ const selected = sources.reduce((best, next) => area(next) < area(best) ? best : next, sources[0])
|
|
44
|
+
+ const largest = typeof selected === 'number' ? Image.resolveAssetSource(selected) : selected
|
|
45
|
+
+ // RN Image copies source dimensions into its layout; let the container set the size.
|
|
46
|
+
+ return typeof largest === 'object'
|
|
47
|
+
+ ? { uri: largest.uri, headers: 'headers' in largest ? largest.headers : undefined, scale: largest.scale }
|
|
48
|
+
+ : largest
|
|
49
|
+
+}
|
|
50
|
+
+
|
|
51
|
+
+const FastImageComponent = forwardRef<FastImageRef, FastImageProps>(({
|
|
52
|
+
+ source, objectFit = 'cover', tintColor, placeholder, defaultSource,
|
|
53
|
+
+ onLoadStart, onProgress, onLoad, onError, onLoadEnd, style, ...props
|
|
54
|
+
+}, ref) => {
|
|
55
|
+
+ const view = useRef<View>(null)
|
|
56
|
+
+ const [attempt, setAttempt] = useState(0)
|
|
57
|
+
+ const [loaded, setLoaded] = useState(false)
|
|
58
|
+
+ useImperativeHandle(ref, () => Object.assign(view.current ?? {}, { reload: () => { setLoaded(false); setAttempt(value => value + 1) } }) as FastImageRef, [])
|
|
59
|
+
+ const fallback = typeof placeholder === 'number' ? placeholder
|
|
60
|
+
+ : typeof placeholder === 'string' ? { uri: placeholder }
|
|
61
|
+
+ : placeholder && 'uri' in placeholder && placeholder.uri ? { uri: placeholder.uri, headers: placeholder.headers }
|
|
62
|
+
+ : defaultSource
|
|
63
|
+
+ return <View ref={view} {...props} style={[styles.container, style]}>
|
|
64
|
+
+ {!loaded && fallback !== undefined && <Image source={imageSource(fallback) as never} resizeMode={fits[objectFit]} style={StyleSheet.absoluteFill} />}
|
|
65
|
+
+ <Image
|
|
66
|
+
+ key={attempt}
|
|
67
|
+
+ source={imageSource(source) as never}
|
|
68
|
+
+ resizeMode={fits[objectFit]}
|
|
69
|
+
+ tintColor={tintColor}
|
|
70
|
+
+ style={[StyleSheet.absoluteFill, tintColor === undefined ? null : { tintColor }]}
|
|
71
|
+
+ onLoadStart={() => { setLoaded(false); onLoadStart?.() }}
|
|
72
|
+
+ onProgress={event => onProgress?.({ nativeEvent: { loaded: event.nativeEvent.loaded, total: event.nativeEvent.total } } as never)}
|
|
73
|
+
+ onLoad={event => {
|
|
74
|
+
+ const loaded = (width: number, height: number) => {
|
|
75
|
+
+ setLoaded(true)
|
|
76
|
+
+ onLoad?.({ nativeEvent: { width, height } })
|
|
77
|
+
+ onLoadEnd?.({ ok: true, width, height })
|
|
78
|
+
+ }
|
|
79
|
+
+ // React Native macOS scales a 1x image's size by the screen's; getSize reads its pixels.
|
|
80
|
+
+ const { uri, width, height } = event.nativeEvent.source
|
|
81
|
+
+ if (uri) Image.getSize(uri).then(size => loaded(size.width, size.height), () => loaded(width, height))
|
|
82
|
+
+ else loaded(width, height)
|
|
83
|
+
+ }}
|
|
84
|
+
+ onError={event => {
|
|
85
|
+
+ const error = String(event.nativeEvent.error)
|
|
86
|
+
+ onError?.({ nativeEvent: { error } })
|
|
87
|
+
+ onLoadEnd?.({ ok: false, error })
|
|
88
|
+
+ }}
|
|
89
|
+
+ />
|
|
90
|
+
+ </View>
|
|
91
|
+
+})
|
|
92
|
+
+FastImageComponent.displayName = 'FastImage'
|
|
93
|
+
+
|
|
94
|
+
+const statics: FastImageStaticProperties = {
|
|
95
|
+
+ resizeMode,
|
|
96
|
+
+ priority,
|
|
97
|
+
+ cacheControl,
|
|
98
|
+
+ preload: sources => Promise.all(sources.map(async (source): Promise<PreloadResult> => {
|
|
99
|
+
+ if (!source?.uri) return { ok: false, uri: source?.uri, error: 'FastImage.preload needs a uri on macOS' }
|
|
100
|
+
+ try {
|
|
101
|
+
+ await Image.prefetch(source.uri)
|
|
102
|
+
+ const { width, height } = await Image.getSize(source.uri)
|
|
103
|
+
+ return { ok: true, uri: source.uri, width, height }
|
|
104
|
+
+ } catch (error) {
|
|
105
|
+
+ return { ok: false, uri: source.uri, error: String(error) }
|
|
106
|
+
+ }
|
|
107
|
+
+ })),
|
|
108
|
+
+ clearMemoryCache: () => unsupported('clearMemoryCache') as Promise<ClearCacheResult>,
|
|
109
|
+
+ clearDiskCache: () => unsupported('clearDiskCache') as Promise<ClearCacheResult>,
|
|
110
|
+
+ getCachePath: () => unsupported('getCachePath') as never,
|
|
111
|
+
+ writeToCache: () => unsupported('writeToCache') as never,
|
|
112
|
+
+ configureCache: () => unsupported('configureCache') as never,
|
|
113
|
+
+ setDefaults: () => {},
|
|
114
|
+
+}
|
|
115
|
+
+
|
|
116
|
+
+const FastImage = Object.assign(FastImageComponent, statics)
|
|
117
|
+
+
|
|
118
|
+
+export const FastImageBackground = forwardRef<View, FastImageBackgroundProps>(
|
|
119
|
+
+ ({ style, imageStyle, imageRef, imageProps, children, ...props }, ref) => {
|
|
120
|
+
+ const [image, container] = splitBackgroundProps(props, imageProps)
|
|
121
|
+
+ return <View ref={ref} {...container} style={style}>
|
|
122
|
+
+ <FastImageComponent {...image} style={[StyleSheet.absoluteFill, imageStyle]} ref={imageRef} />
|
|
123
|
+
+ {children}
|
|
124
|
+
+ </View>
|
|
125
|
+
+ },
|
|
126
|
+
+)
|
|
127
|
+
+FastImageBackground.displayName = 'FastImageBackground'
|
|
128
|
+
+
|
|
129
|
+
+const styles = StyleSheet.create({ container: { overflow: 'hidden' } })
|
|
130
|
+
+
|
|
131
|
+
+export default FastImage
|