Skip to content

Commit

Permalink
iOS: Fix issue with keyboard popping up after file picker.
Browse files Browse the repository at this point in the history
iOS kb APIs are crazy
  • Loading branch information
hrydgard committed May 25, 2024
1 parent f2b36f0 commit 80595d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
32 changes: 22 additions & 10 deletions UI/DarwinFileSystemServices.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#include "ppsspp_config.h"
#include "Core/Config.h"
#include "Common/Log.h"
#include "DarwinFileSystemServices.h"
#include "../ios/ViewControllerCommon.h"
#include <dispatch/dispatch.h>
#include <CoreServices/CoreServices.h>

Expand All @@ -24,18 +26,27 @@ @interface DocumentPickerDelegate : NSObject <UIDocumentPickerDelegate>

@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
Expand Down Expand Up @@ -77,6 +88,7 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocum
// 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) {
Expand Down Expand Up @@ -144,4 +156,4 @@ void RestartMacApp() {
[task launch];
exit(0);
#endif
}
}
15 changes: 9 additions & 6 deletions ios/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -448,18 +448,14 @@ -(void) deleteBackward {
INFO_LOG(SYSTEM, "Backspace");
}

-(BOOL) hasText
{
return YES;
}

-(void) insertText:(NSString *)text
{
std::string str = std::string([text UTF8String]);
INFO_LOG(SYSTEM, "Chars: %s", str.c_str());
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;
Expand All @@ -470,17 +466,24 @@ -(void) insertText:(NSString *)text

-(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];
});
}
Expand Down

0 comments on commit 80595d7

Please sign in to comment.