iOS: Fix issue with keyboard popping up after file picker.

iOS kb APIs are crazy
This commit is contained in:
Henrik Rydgård committed 2024-05-26 09:23:57 +02:00
1 parent 2a3f8af650
commit 081bf51eac
2 files changed
+31 -16

No files matched your search

+22 -10
View File
@@ -7,6 +7,7 @@
#include "ppsspp_config.h"
#include "Core/Config.h"
#include "Common/Log.h"
#include "DarwinFileSystemServices.h"
#include <dispatch/dispatch.h>
#include <CoreServices/CoreServices.h>
@@ -16,6 +17,7 @@
#endif
#if __has_include(<UIKit/UIKit.h>)
#include "../ios/ViewControllerCommon.h"
#include <UIKit/UIKit.h>
@interface DocumentPickerDelegate : NSObject <UIDocumentPickerDelegate>
@@ -24,18 +26,27 @@
@implementation DocumentPickerDelegate
-(instancetype)initWithCallback: (DarwinDirectoryPanelCallback)callback {
if (self = [super init]) {
self.callback = callback;
}
return self;
if (self = [super init]) {
self.callback = callback;
}
return self;
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
if (urls.count >= 1)
- (void)didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
if (urls.count >= 1)
self.callback(true, Path(urls[0].path.UTF8String));
else
self.callback(false, Path());
else
self.callback(false, Path());
INFO_LOG(SYSTEM, "Callback processed, pre-emptively hide keyboard");
[sharedViewController hideKeyboard];
}
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
self.callback(false, Path());
INFO_LOG(SYSTEM, "Picker cancelled, pre-emptively hide keyboard");
[sharedViewController hideKeyboard];
}
@end
@@ -77,6 +88,7 @@ void DarwinFileSystemServices::presentDirectoryPanel(
// panel.allowedFileTypes = @[(__bridge NSString *)kUTTypeFolder];
NSModalResponse modalResponse = [panel runModal];
INFO_LOG(SYSTEM, "Mac: Received response from modal");
if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) {
callback(true, Path(panel.URLs.firstObject.path.UTF8String));
} else if (modalResponse == NSModalResponseCancel) {
@@ -144,4 +156,4 @@ void RestartMacApp() {
[task launch];
exit(0);
#endif
}
}
+9 -6
View File
@@ -448,11 +448,6 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
INFO_LOG(SYSTEM, "Backspace");
}
-(BOOL) hasText
{
return YES;
}
-(void) insertText:(NSString *)text
{
std::string str = std::string([text UTF8String]);
@@ -460,6 +455,7 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
UTF8 chars(str);
while (!chars.end()) {
uint32_t codePoint = chars.next();
INFO_LOG(SYSTEM, "Codepoint#: %d", codePoint);
KeyInput input{};
input.deviceId = DEVICE_ID_KEYBOARD;
input.flags = KEY_CHAR;
@@ -470,17 +466,24 @@ void GLRenderLoop(IOSGLESContext *graphicsContext) {
-(BOOL) canBecomeFirstResponder
{
return YES;
return true;
}
-(BOOL) hasText
{
return true;
}
-(void) showKeyboard {
dispatch_async(dispatch_get_main_queue(), ^{
INFO_LOG(SYSTEM, "becomeFirstResponder");
[self becomeFirstResponder];
});
}
-(void) hideKeyboard {
dispatch_async(dispatch_get_main_queue(), ^{
INFO_LOG(SYSTEM, "resignFirstResponder");
[self resignFirstResponder];
});
}