@fluentui-react-native/callout 0.19.33 → 0.19.34
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/CHANGELOG.json +16 -1
- package/CHANGELOG.md +10 -2
- package/macos/Callout.swift +36 -28
- package/macos/GuardedEventMonitor.swift +10 -12
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,22 @@
|
|
|
2
2
|
"name": "@fluentui-react-native/callout",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Mon, 21 Mar 2022 01:47:26 GMT",
|
|
6
|
+
"tag": "@fluentui-react-native/callout_v0.19.34",
|
|
7
|
+
"version": "0.19.34",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "sanajmi@microsoft.com",
|
|
12
|
+
"package": "@fluentui-react-native/callout",
|
|
13
|
+
"commit": "b772dfe4542b7032f216bf5c2faa807c695fa2a7",
|
|
14
|
+
"comment": "width -> maxWidth"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Fri, 18 Mar 2022 07:19:17 GMT",
|
|
6
21
|
"tag": "@fluentui-react-native/callout_v0.19.33",
|
|
7
22
|
"version": "0.19.33",
|
|
8
23
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
# Change Log - @fluentui-react-native/callout
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 21 Mar 2022 01:47:26 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.19.34
|
|
8
|
+
|
|
9
|
+
Mon, 21 Mar 2022 01:47:26 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- width -> maxWidth (sanajmi@microsoft.com)
|
|
14
|
+
|
|
7
15
|
## 0.19.33
|
|
8
16
|
|
|
9
|
-
Fri, 18 Mar 2022 07:
|
|
17
|
+
Fri, 18 Mar 2022 07:19:17 GMT
|
|
10
18
|
|
|
11
19
|
### Patches
|
|
12
20
|
|
package/macos/Callout.swift
CHANGED
|
@@ -85,39 +85,47 @@ class CalloutView: RCTView, CalloutWindowLifeCycleDelegate {
|
|
|
85
85
|
|
|
86
86
|
updateCalloutFrameToAnchor()
|
|
87
87
|
calloutWindow.makeKeyAndOrderFront(self)
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
// Dismiss the Callout if the window is no longer active.
|
|
90
90
|
NotificationCenter.default.addObserver(self, selector: #selector(dismissCallout), name: NSApplication.didResignActiveNotification, object: nil)
|
|
91
91
|
|
|
92
|
-
mouseEventMonitor.addLocalMonitorForEvents(matching: .
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
mouseEventMonitor.addLocalMonitorForEvents(matching: .leftMouseDown, handler: { [weak self] (event) -> NSEvent? in
|
|
93
|
+
func isClickInsideWindowHierarchy(window: NSWindow?, event: NSEvent) -> Bool {
|
|
94
|
+
guard let window = window else {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
guard let clickedWindow = event.window else {
|
|
98
|
+
return false
|
|
95
99
|
}
|
|
96
100
|
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
// Did the click happened in our own window?
|
|
100
|
-
if (clickedWindow.isEqual(to: self) ) {
|
|
101
|
-
shouldDismissCallout = false
|
|
102
|
-
|
|
103
|
-
// Are we a child window of a Callout (e.g: a ContextualMenu submenu), where the click happened in our parent?
|
|
104
|
-
} else if (clickedWindow.isEqual(to: self?.calloutWindow.parent as? CalloutWindow)) {
|
|
105
|
-
shouldDismissCallout = false
|
|
101
|
+
var isClickInHierarchy = false
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
103
|
+
if (window.isEqual(to: clickedWindow)) {
|
|
104
|
+
isClickInHierarchy = true
|
|
105
|
+
} else {
|
|
106
|
+
if let childWindows = window.childWindows {
|
|
107
|
+
for childWindow in childWindows {
|
|
108
|
+
isClickInHierarchy = isClickInsideWindowHierarchy(window: childWindow, event: event)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
114
111
|
}
|
|
115
112
|
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
|
|
113
|
+
return isClickInHierarchy
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var window: NSWindow? = self?.calloutWindow
|
|
117
|
+
while (window?.parent as? CalloutWindow != nil) {
|
|
118
|
+
window = window?.parent
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!isClickInsideWindowHierarchy(window: window, event: event)) {
|
|
122
|
+
self?.dismissCallout()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return event
|
|
126
|
+
})
|
|
127
|
+
|
|
119
128
|
isCalloutWindowShown = true
|
|
120
|
-
|
|
121
129
|
onShowCallout()
|
|
122
130
|
}
|
|
123
131
|
|
|
@@ -139,7 +147,7 @@ class CalloutView: RCTView, CalloutWindowLifeCycleDelegate {
|
|
|
139
147
|
|
|
140
148
|
NotificationCenter.default.removeObserver(self)
|
|
141
149
|
mouseEventMonitor.removeMonitor()
|
|
142
|
-
|
|
150
|
+
|
|
143
151
|
isCalloutWindowShown = false
|
|
144
152
|
}
|
|
145
153
|
|
|
@@ -328,7 +336,7 @@ class CalloutView: RCTView, CalloutWindowLifeCycleDelegate {
|
|
|
328
336
|
private var anchorView: NSView?
|
|
329
337
|
|
|
330
338
|
/// The view we forward Callout's Children to. It's hosted within the CalloutWindow's
|
|
331
|
-
/// view
|
|
339
|
+
/// view hierarchy, ensuring our React Views are not placed in the main window.
|
|
332
340
|
private lazy var proxyView: NSView = {
|
|
333
341
|
let visualEffectView = FlippedVisualEffectView()
|
|
334
342
|
visualEffectView.translatesAutoresizingMaskIntoConstraints = false
|
|
@@ -363,9 +371,9 @@ class CalloutView: RCTView, CalloutWindowLifeCycleDelegate {
|
|
|
363
371
|
}
|
|
364
372
|
return window
|
|
365
373
|
}()
|
|
366
|
-
|
|
374
|
+
|
|
367
375
|
private var mouseEventMonitor = GuardedEventMonitor()
|
|
368
|
-
|
|
376
|
+
|
|
369
377
|
private var isCalloutWindowShown = false
|
|
370
378
|
}
|
|
371
379
|
|
|
@@ -2,28 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
/// NSEvent localMonitors are an _old_ API that requires you to do some memory management yourself.
|
|
4
4
|
/// You _must_ call `removeMonitor`exactly once per monitor created from. This helper class enforces
|
|
5
|
-
///
|
|
5
|
+
/// we set the reference to nil after `removeMonitor` so that subsequent calls don't cause an over release.
|
|
6
|
+
/// One instance should only be used to allocate and manage one NSEvent monitor.
|
|
6
7
|
/// https://developer.apple.com/documentation/appkit/nsevent/1533709-removemonitor
|
|
7
8
|
internal class GuardedEventMonitor: Any {
|
|
8
|
-
|
|
9
|
-
private var isMonitorAllocated = false
|
|
9
|
+
|
|
10
10
|
private var allocatedMonitor: Any?
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
func addLocalMonitorForEvents(matching mask: NSEvent.EventTypeMask, handler block: @escaping (NSEvent) -> NSEvent?) {
|
|
14
|
-
if (
|
|
13
|
+
if (allocatedMonitor == nil) {
|
|
15
14
|
allocatedMonitor = NSEvent.addLocalMonitorForEvents(matching: mask, handler: block)
|
|
16
|
-
isMonitorAllocated = true
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
|
-
|
|
17
|
+
|
|
20
18
|
func removeMonitor() {
|
|
21
|
-
if
|
|
22
|
-
NSEvent.removeMonitor(
|
|
23
|
-
|
|
19
|
+
if let monitor = allocatedMonitor {
|
|
20
|
+
NSEvent.removeMonitor(monitor)
|
|
21
|
+
allocatedMonitor = nil
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
|
-
|
|
24
|
+
|
|
27
25
|
deinit {
|
|
28
26
|
removeMonitor()
|
|
29
27
|
}
|