Skip to content

Commit a7dde15

Browse files
committed
fix(runtime/{webview,window}: fix swipe gesture delegates for ios
1 parent c521a00 commit a7dde15

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

src/runtime/webview/webview.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,21 @@ int lastY = 0;
732732

733733
#if SOCKET_RUNTIME_PLATFORM_IOS
734734
@implementation SSCWebViewController
735+
- (BOOL) gestureRecognizer: (UIGestureRecognizer*) gestureRecognizer
736+
shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer*) otherGestureRecognizer
737+
{
738+
return YES;
739+
}
740+
741+
- (BOOL) gestureRecognizer: (UIGestureRecognizer*) gestureRecognizer
742+
shouldReceiveTouch: (UITouch*) touch
743+
{
744+
if ([touch.view isDescendantOfView: self.webview]) {
745+
return NO;
746+
}
747+
748+
return YES;
749+
}
735750
@end
736751
#endif
737752
#endif

src/runtime/webview/webview.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ namespace ssc::runtime::webview {
9393
#if SOCKET_RUNTIME_PLATFORM_IOS
9494
@interface SSCWebViewController : UIViewController<UIGestureRecognizerDelegate>
9595
@property (nonatomic, strong) SSCWebView* webview;
96+
97+
- (BOOL) gestureRecognizer: (UIGestureRecognizer*) gestureRecognizer
98+
shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer*) otherGestureRecognizer;
99+
100+
- (BOOL) gestureRecognizer: (UIGestureRecognizer*) gestureRecognizer
101+
shouldReceiveTouch: (UITouch*) touch;
96102
@end
97103
#endif
98104
#endif

src/runtime/window.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace ssc::runtime::bridge {
4343
UIScrollViewDelegate,
4444
WKScriptMessageHandler
4545
>
46+
- (void) handleEdgePanGesture: (UIScreenEdgePanGestureRecognizer*) gesture;
4647
#else
4748
NSObject <
4849
NSWindowDelegate,

src/runtime/window/apple.mm

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,25 @@ - (void) scrollViewDidScroll: (UIScrollView*) scrollView {
175175

176176
- (void) handleEdgePanGesture: (UIScreenEdgePanGestureRecognizer*) gesture {
177177
auto window = (Window*) objc_getAssociatedObject(self, "window");
178-
CGPoint translation = [gesture translationInView:self.view];
179-
CGFloat progress = translation.x / self.view.bounds.size.width;
178+
if (!window) {
179+
return;
180+
}
181+
CGPoint translation = [gesture translationInView: window->viewController.view];
182+
CGFloat progress = translation.x / window->viewController.view.bounds.size.width;
180183
progress = fmin(fmax(progress, 0.0), 1.0);
181184
if (
182185
gesture.state == UIGestureRecognizerStateEnded ||
183186
gesture.state == UIGestureRecognizerStateCancelled
184187
) {
185188
if (progress > 0.3) {
186189
if (window && window->webview.canGoBack) {
187-
[window->webview.goBack];
190+
[window->webview goBack];
188191
} else {
189-
window->close();
190-
// [self.navigationController popViewControllerAnimated:YES];
192+
const auto app = App::sharedApplication();
193+
const auto index = window->index;
194+
app->dispatch([index, app](){
195+
app->runtime.windowManager.destroyWindow(index);
196+
});
191197
}
192198
}
193199
}
@@ -452,14 +458,15 @@ - (void) handleEdgePanGesture: (UIScreenEdgePanGestureRecognizer*) gesture {
452458

453459
#if SOCKET_RUNTIME_PLATFORM_IOS
454460
this->webview.allowsBackForwardNavigationGestures = NO;
455-
if (userConfig["webview_navigator_enable_navigation_gestures"] == "true") {
461+
if (!this->options.headless && userConfig["webview_navigator_enable_navigation_gestures"] == "true") {
456462
auto edgePanGesture = [[UIScreenEdgePanGestureRecognizer alloc]
457463
initWithTarget: this->windowDelegate
458-
action: @selector(handleEdgePanGesture:)
464+
action: @selector(handleEdgePanGesture:)
459465
];
460466
edgePanGesture.edges = UIRectEdgeLeft;
461-
edgePanGesture.delegate = self;
467+
edgePanGesture.delegate = this->viewController;
462468
[this->viewController.view addGestureRecognizer: edgePanGesture];
469+
[this->webview addGestureRecognizer: edgePanGesture];
463470
}
464471
#else
465472
this->webview.allowsBackForwardNavigationGestures = userConfig["webview_navigator_enable_navigation_gestures"] == "true";
@@ -798,6 +805,17 @@ - (void) handleEdgePanGesture: (UIScreenEdgePanGestureRecognizer*) gesture {
798805
}
799806

800807
if (this->webview != nullptr) {
808+
#if SOCKET_RUNTIME_PLATFORM_IOS
809+
const auto managedWindow = app->runtime.windowManager.getWindow(this->index);
810+
if (managedWindow) {
811+
const auto json = managedWindow->json();
812+
for (auto window : app->runtime.windowManager.windows) {
813+
if (window != nullptr && window->index != this->index) {
814+
window->eval(getEmitToRenderProcessJavaScript("windowclosed", json.str()));
815+
}
816+
}
817+
}
818+
#endif
801819
objc_removeAssociatedObjects(this->webview);
802820
[this->webview stopLoading];
803821
[this->webview.configuration.userContentController removeAllScriptMessageHandlers];
@@ -833,9 +851,13 @@ - (void) handleEdgePanGesture: (UIScreenEdgePanGestureRecognizer*) gesture {
833851
}
834852

835853
this->window.titleBarView = nullptr;
836-
this->window = nullptr;
837854
#endif
855+
this->window = nullptr;
838856
}
857+
858+
#if SOCKET_RUNTIME_PLATFORM_IOS
859+
this->viewController = nullptr;
860+
#endif
839861
}
840862

841863
void Window::maximize () {

src/runtime/window/manager.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,13 @@ namespace ssc::runtime::window {
153153

154154
this->windows[index] = nullptr;
155155
if (window->options.shouldExitApplicationOnClose) {
156-
static_cast<runtime::Runtime&>(this->context).dispatch([window]() {
156+
static_cast<runtime::Runtime&>(this->context).dispatch([this, index, window]() {
157157
window->exit(0);
158+
static_cast<runtime::Runtime&>(this->context).bridgeManager.remove(index);
158159
});
159160
} else {
160161
window->kill();
162+
static_cast<runtime::Runtime&>(this->context).bridgeManager.remove(index);
161163
}
162164
}
163165
}

0 commit comments

Comments
 (0)