浏览代码

[iOS] use SDL's standard input handling for in-game chat

Andrey Filipenkov 3 年之前
父节点
当前提交
593df25df5
共有 3 个文件被更改,包括 0 次插入59 次删除
  1. 0 2
      client/ios/GameChatKeyboardHandler.h
  2. 0 37
      client/ios/GameChatKeyboardHandler.m
  3. 0 20
      client/ios/startSDL.mm

+ 0 - 2
client/ios/GameChatKeyboardHandler.h

@@ -14,8 +14,6 @@ NS_ASSUME_NONNULL_BEGIN
 
 
 @interface GameChatKeyboardHandler : NSObject
 @interface GameChatKeyboardHandler : NSObject
 
 
-@property (nonatomic, weak) UITextField * textFieldSDL;
-
 - (void)triggerInput;
 - (void)triggerInput;
 
 
 @end
 @end

+ 0 - 37
client/ios/GameChatKeyboardHandler.m

@@ -24,13 +24,6 @@ static void sendKeyEvent(SDL_KeyCode keyCode)
 	SDL_PushEvent(&keyEvent);
 	SDL_PushEvent(&keyEvent);
 }
 }
 
 
-static CGRect keyboardFrame(NSNotification * n, NSString * userInfoKey)
-{
-	return [n.userInfo[userInfoKey] CGRectValue];
-}
-static CGRect keyboardFrameBegin(NSNotification * n) { return keyboardFrame(n, UIKeyboardFrameBeginUserInfoKey); }
-static CGRect keyboardFrameEnd  (NSNotification * n) { return keyboardFrame(n, UIKeyboardFrameEndUserInfoKey); }
-
 
 
 @interface GameChatKeyboardHandler ()
 @interface GameChatKeyboardHandler ()
 @property (nonatomic) BOOL wasChatMessageSent;
 @property (nonatomic) BOOL wasChatMessageSent;
@@ -42,56 +35,26 @@ static CGRect keyboardFrameEnd  (NSNotification * n) { return keyboardFrame(n, U
 	__auto_type notificationCenter = NSNotificationCenter.defaultCenter;
 	__auto_type notificationCenter = NSNotificationCenter.defaultCenter;
 	[notificationCenter addObserver:self selector:@selector(textDidBeginEditing:) name:UITextFieldTextDidBeginEditingNotification object:nil];
 	[notificationCenter addObserver:self selector:@selector(textDidBeginEditing:) name:UITextFieldTextDidBeginEditingNotification object:nil];
 	[notificationCenter addObserver:self selector:@selector(textDidEndEditing:) name:UITextFieldTextDidEndEditingNotification object:nil];
 	[notificationCenter addObserver:self selector:@selector(textDidEndEditing:) name:UITextFieldTextDidEndEditingNotification object:nil];
-	[notificationCenter addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
-	[notificationCenter addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
 
 
 	self.wasChatMessageSent = NO;
 	self.wasChatMessageSent = NO;
 	sendKeyEvent(SDLK_TAB);
 	sendKeyEvent(SDLK_TAB);
 }
 }
 
 
-- (void)positionTextFieldAboveKeyboardRect:(CGRect)kbFrame {
-	__auto_type r = kbFrame;
-	r.size.height = CGRectGetHeight(self.textFieldSDL.frame);
-	r.origin.y -= r.size.height;
-	self.textFieldSDL.frame = r;
-}
-
 #pragma mark - Notifications
 #pragma mark - Notifications
 
 
 - (void)textDidBeginEditing:(NSNotification *)n {
 - (void)textDidBeginEditing:(NSNotification *)n {
-	self.textFieldSDL.hidden = NO;
-	self.textFieldSDL.text = nil;
-
 	// watch for pressing Return to ignore sending Escape key after keyboard is closed
 	// watch for pressing Return to ignore sending Escape key after keyboard is closed
 	SDL_AddEventWatch(watchReturnKey, (__bridge void *)self);
 	SDL_AddEventWatch(watchReturnKey, (__bridge void *)self);
 }
 }
 
 
 - (void)textDidEndEditing:(NSNotification *)n {
 - (void)textDidEndEditing:(NSNotification *)n {
 	[NSNotificationCenter.defaultCenter removeObserver:self];
 	[NSNotificationCenter.defaultCenter removeObserver:self];
-	self.textFieldSDL.hidden = YES;
 
 
 	// discard chat message
 	// discard chat message
 	if(!self.wasChatMessageSent)
 	if(!self.wasChatMessageSent)
 		sendKeyEvent(SDLK_ESCAPE);
 		sendKeyEvent(SDLK_ESCAPE);
 }
 }
 
 
-- (void)keyboardWillChangeFrame:(NSNotification *)n {
-	// animate textfield together with keyboard
-	[UIView performWithoutAnimation:^{
-		[self positionTextFieldAboveKeyboardRect:keyboardFrameBegin(n)];
-	}];
-
-	NSTimeInterval kbAnimationDuration = [n.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
-	NSUInteger kbAnimationCurve = [n.userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue];
-	[UIView animateWithDuration:kbAnimationDuration delay:0 options:(kbAnimationCurve << 16) animations:^{
-		[self positionTextFieldAboveKeyboardRect:keyboardFrameEnd(n)];
-	} completion:nil];
-}
-
-- (void)keyboardDidChangeFrame:(NSNotification *)n {
-	[self positionTextFieldAboveKeyboardRect:keyboardFrameEnd(n)];
-}
-
 @end
 @end
 
 
 
 

+ 0 - 20
client/ios/startSDL.mm

@@ -33,26 +33,6 @@
 
 
     UIView * view = [object valueForKeyPath:keyPath];
     UIView * view = [object valueForKeyPath:keyPath];
 
 
-    UITextField * textField;
-    for (UIView * v in view.subviews) {
-        if ([v isKindOfClass:[UITextField class]]) {
-            textField = (UITextField *)v;
-            break;
-        }
-    }
-
-	auto r = textField.frame;
-	r.size.height = 40;
-	textField.frame = r;
-    self.gameChatHandler.textFieldSDL = textField;
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
-	if(@available(iOS 13.0, *))
-		textField.backgroundColor = UIColor.systemBackgroundColor;
-	else
-#endif
-		textField.backgroundColor = UIColor.whiteColor;
-
     auto longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
     auto longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
     longPress.minimumPressDuration = 0.2;
     longPress.minimumPressDuration = 0.2;
     [view addGestureRecognizer:longPress];
     [view addGestureRecognizer:longPress];