This repository was archived by the owner on Nov 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +79
-0
lines changed Expand file tree Collapse file tree 6 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -8424,6 +8424,14 @@ declare class SwitchComponent extends React.Component<SwitchProps> {}
8424
8424
declare const SwitchBase : Constructor < NativeMethodsMixin > & typeof SwitchComponent ;
8425
8425
export class Switch extends SwitchBase { }
8426
8426
8427
+ /**
8428
+ * The `WindowDrag` component provides an area where the mouse can left-click
8429
+ * and then drag in order to move the native `RCTWindow` that contains this view.
8430
+ *
8431
+ * @platform macos
8432
+ */
8433
+ export class WindowDrag extends React . Component < ViewProps > { }
8434
+
8427
8435
/**
8428
8436
* NOTE: `VibrationIOS` is being deprecated. Use `Vibration` instead.
8429
8437
*
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule WindowDrag
10
+ * @noflow
11
+ */
12
+ 'use strict' ;
13
+
14
+ const React = require ( 'react' ) ;
15
+ const ReactNative = require ( 'ReactNative' ) ;
16
+ const TouchableWithoutFeedback = require ( 'TouchableWithoutFeedback' ) ;
17
+ const UIManager = require ( 'UIManager' ) ;
18
+ const View = require ( 'View' ) ;
19
+
20
+ const DRAG_REF = 'drag' ;
21
+
22
+ class WindowDrag extends React . Component {
23
+ render ( ) {
24
+ return (
25
+ < TouchableWithoutFeedback
26
+ onPressIn = { ( ) => (
27
+ UIManager . dispatchViewManagerCommand (
28
+ ReactNative . findNodeHandle ( this . refs [ DRAG_REF ] ) ,
29
+ UIManager . RCTView . Commands . performWindowDrag ,
30
+ null
31
+ )
32
+ ) } >
33
+ < View ref = { DRAG_REF } { ...this . props } />
34
+ </ TouchableWithoutFeedback >
35
+ ) ;
36
+ }
37
+ }
38
+
39
+ module . exports = WindowDrag ;
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ const ReactNative = {
60
60
get ViewPagerAndroid ( ) { return require ( 'ViewPagerAndroid' ) ; } ,
61
61
get VirtualizedList ( ) { return require ( 'VirtualizedList' ) ; } ,
62
62
get WebView ( ) { return require ( 'WebView' ) ; } ,
63
+ get WindowDrag ( ) { return require ( 'WindowDrag' ) ; } ,
63
64
64
65
// APIs
65
66
get ActionSheetIOS ( ) { return require ( 'ActionSheetIOS' ) ; } ,
Original file line number Diff line number Diff line change 22
22
#import " RCTUIManagerUtils.h"
23
23
#import " RCTUtils.h"
24
24
#import " RCTView.h"
25
+ #import " RCTWindow.h"
25
26
#import " NSView+React.h"
26
27
#import " RCTConvert+Transform.h"
27
28
@@ -364,4 +365,28 @@ - (RCTShadowView *)shadowView
364
365
365
366
RCT_EXPORT_SHADOW_PROPERTY(direction, YGDirection)
366
367
368
+ RCT_EXPORT_METHOD(performWindowDrag:(nonnull NSNumber *)reactTag)
369
+ {
370
+ [self .bridge.uiManager addUIBlock:
371
+ ^(__unused RCTUIManager *uiManager, NSDictionary <NSNumber *, RCTView *> *viewRegistry) {
372
+
373
+ RCTView *view = viewRegistry[reactTag];
374
+ if (!view || ![view isKindOfClass: [RCTView class ]]) {
375
+ RCTLogError (@" Cannot find RCTView with tag #%@ " , reactTag);
376
+ return ;
377
+ }
378
+
379
+ RCTWindow *window = (RCTWindow *)view.window ;
380
+ if (!window || ![window isKindOfClass: [RCTWindow class ]]) {
381
+ RCTLogError (@" Expected RCTView.window to be a RCTWindow, but got a %@ " , window.className );
382
+ return ;
383
+ }
384
+
385
+ NSEvent *event = window.lastLeftMouseEvent ;
386
+ if (event && event.type != NSLeftMouseUp ) {
387
+ [window performWindowDragWithEvent: window.lastLeftMouseEvent];
388
+ }
389
+ }];
390
+ }
391
+
367
392
@end
Original file line number Diff line number Diff line change 24
24
// Only exists between mouseDown and mouseUp events (may not be a React view)
25
25
@property (nullable , strong ) NSView *clickOrigin;
26
26
27
+ @property (nonatomic , readonly ) NSEvent *lastLeftMouseEvent;
28
+
27
29
@end
Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ - (void)sendEvent:(NSEvent *)event
126
126
127
127
if (_clickTarget) {
128
128
if (type == NSEventTypeLeftMouseDragged) {
129
+ _lastLeftMouseEvent = event;
129
130
if (_clickType == NSEventTypeLeftMouseDown) {
130
131
[self _sendTouchEvent: @" touchMove" ];
131
132
}
@@ -162,6 +163,7 @@ - (void)sendEvent:(NSEvent *)event
162
163
}
163
164
164
165
if (type == NSEventTypeLeftMouseDown) {
166
+ _lastLeftMouseEvent = event;
165
167
[self _sendTouchEvent: @" touchStart" ];
166
168
}
167
169
@@ -172,6 +174,8 @@ - (void)sendEvent:(NSEvent *)event
172
174
}
173
175
174
176
if (type == NSEventTypeLeftMouseUp) {
177
+ _lastLeftMouseEvent = event;
178
+
175
179
if (_clickType == NSEventTypeLeftMouseDown) {
176
180
[self _sendTouchEvent: @" touchEnd" ];
177
181
_clickTarget = nil ;
You can’t perform that action at this time.
0 commit comments