From c533c614bdd27cf4cd7c507ac955d8418dfbee49 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Fri, 12 Feb 2021 08:04:25 +0700 Subject: [PATCH] Try to fix iOS 12 compatibility; Fixes enter key --- Natives/LauncherViewController.m | 2 +- Natives/LoginViewController.m | 2 +- Natives/SceneDelegate.m | 1 + Natives/SurfaceViewController.m | 19 +++++++------------ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Natives/LauncherViewController.m b/Natives/LauncherViewController.m index 9cf83d37..0e430c21 100644 --- a/Natives/LauncherViewController.m +++ b/Natives/LauncherViewController.m @@ -32,7 +32,7 @@ UITextField* versionTextField; // Update color mode once if(@available(iOS 13.0, *)) { - [self traitCollectionDidChange:nil]; + // [self traitCollectionDidChange:nil]; } else { self.view.backgroundColor = [UIColor whiteColor]; } diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 1e516e4b..661e60d8 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -67,7 +67,7 @@ void loginAccountInput(UINavigationController *controller, int type, char* usern // Update color mode once if(@available(iOS 13.0, *)) { - [self traitCollectionDidChange:nil]; + // [self traitCollectionDidChange:nil]; } else { self.view.backgroundColor = [UIColor whiteColor]; } diff --git a/Natives/SceneDelegate.m b/Natives/SceneDelegate.m index 2f62e2be..65a5da78 100644 --- a/Natives/SceneDelegate.m +++ b/Natives/SceneDelegate.m @@ -19,6 +19,7 @@ self.window.frame = windowScene.coordinateSpace.bounds; self.window.rootViewController = nav; [self.window makeKeyAndVisible]; + [vc traitCollectionDidChange:nil]; } else { } diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index a8c06bbe..6b9ec497 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -48,7 +48,6 @@ UIButton* togglableVisibleButtons[100]; UIView *touchView; UITextField *inputView; BOOL shouldTriggerClick = NO; -BOOL shouldTriggerEnter = NO; // TODO: key modifiers impl @@ -93,7 +92,6 @@ BOOL shouldTriggerEnter = NO; inputView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.0f]; [inputView addTarget:self action:@selector(inputViewDidChange) forControlEvents:UIControlEventEditingChanged]; - [inputView addTarget:self action:@selector(inputViewDidReturn) forControlEvents:UIControlEventEditingDidEnd]; [inputView addTarget:self action:@selector(inputViewDidClick) forControlEvents:UIControlEventTouchDown]; // Custom button @@ -214,7 +212,13 @@ BOOL shouldTriggerEnter = NO; int charLength = [newText length]; //char16_t *charText = [newText UTF16String]; for (int i = 0; i < charLength; i++) { - Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods(NULL, NULL, (jchar) [newText characterAtIndex:i] /* charText[i] */, /* mods */ 0); + unichar currChar = [newText characterAtIndex:i]; + if (currChar == '\n') { + Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(NULL, NULL, GLFW_KEY_ENTER, 0, 1, 0); + Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(NULL, NULL, GLFW_KEY_ENTER, 0, 0, 0); + } else { + Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods(NULL, NULL, (jchar) currChar /* charText[i] */, /* mods */ 0); + } } } @@ -226,14 +230,6 @@ BOOL shouldTriggerEnter = NO; // Zero the input field so user will no longer able to select text inside. inputView.alpha = 0.0f; inputView.text = @" "; - shouldTriggerEnter = YES; -} - --(void)inputViewDidReturn { - if (shouldTriggerEnter == YES) { - Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(NULL, NULL, GLFW_KEY_ENTER, 0, 1, 0); - Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(NULL, NULL, GLFW_KEY_ENTER, 0, 0, 0); - } } int currentVisibility = 1; @@ -248,7 +244,6 @@ ADD_BUTTON_DEF(special_togglebtn) { ADD_BUTTON_DEF(special_keyboard) { if (held == 0) { - shouldTriggerEnter = NO; [inputView resignFirstResponder]; inputView.alpha = 1.0f; inputView.text = @"";