Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCEAGLView:setMarkedText problem in iOS13 #20174

Closed
lxhhuangjin opened this issue Sep 25, 2019 · 87 comments
Closed

CCEAGLView:setMarkedText problem in iOS13 #20174

lxhhuangjin opened this issue Sep 25, 2019 · 87 comments

Comments

@lxhhuangjin
Copy link

  • cocos2d-x version: 3.12
  • devices test on: iPhone
  • developing environments
    • NDK version:
    • Xcode version:
    • VS version:
    • browser type and version:

Steps to Reproduce:
input Chinese in TextField just recieve one charactor in setMarketedText , input number or English both ok.

@lxhhuangjin
Copy link
Author

be the same question with #20050

@wandeli
Copy link

wandeli commented Sep 26, 2019

  • (NSString *)textInRange:(UITextRange *)range
    {
    CCLOG("textInRange");
    if (nil != markedText_) {
    return markedText_;
    }
    return @"";
    }

  • (UITextRange *)markedTextRange
    {
    CCLOG("markedTextRange");
    if (nil != markedText_) {
    return [[[UITextRange alloc] init] autorelease];
    }
    return nil; // Nil if no marked text.
    }

@lxhhuangjin
Copy link
Author

* (NSString *)textInRange:(UITextRange *)range
  {
  CCLOG("textInRange");
  if (nil != markedText_) {
  return markedText_;
  }
  return @"";
  }

* (UITextRange *)markedTextRange
  {
  CCLOG("markedTextRange");
  if (nil != markedText_) {
  return [[[UITextRange alloc] init] autorelease];
  }
  return nil; // Nil if no marked text.
  }

I have tried this code. The input of Chinese is ok. But when i click the screen to close IME. The IME open again. I debug this performance and find i recieved UIKeyboardWillShowNotification.

@minggo
Copy link
Contributor

minggo commented Sep 29, 2019

I don't know what's the problem, i can input Chinese characters with iPhone11(iOS 13).

@lxhhuangjin
Copy link
Author

lxhhuangjin commented Sep 29, 2019

My iPhone X(iOS13) input Chinese in
TextField has problem. The function named setMarkedText just received one charactor I input recently.

@minggo
Copy link
Contributor

minggo commented Sep 29, 2019

What test case did you test?

@lxhhuangjin
Copy link
Author

What test case did you test?

Any input is ok.
eg. First i input 'w', setMarkedText recieved 'w', then input 'd', setMarkedText recieved 'd'. But setMarkedText need recieve 'wd'.

@minggo
Copy link
Contributor

minggo commented Sep 29, 2019

Did you use TextFieldTTF? Please show your test case and the steps to reproduce it. Thanks.

@lxhhuangjin
Copy link
Author

Yes. I use TextFieldTTF for input.
I want to input Chinese like "我的" on iPhone.
So i input 'wd' for the words. But the input result is not correct. The result did not change compared with the input when i open IME.
I debuged for this problem. I fond the problem is the function or setMarkedText.
I think you can reproduce this problem by any iPhone when update to iOS 13. I tried iPhoneXR and iPhoneXS Max.

@minggo
Copy link
Contributor

minggo commented Sep 29, 2019

As i said above, i tested TextInput and change to use Arial, then can input Chinese. You should check your ttf file support Chinese characters.

@lxhhuangjin
Copy link
Author

As i said above, i tested TextInput and change to use Arial, then can input Chinese. You should check your ttf file support Chinese characters.

I can input Chinese properly before i update my iPhone to iOS 13.

@minggo
Copy link
Contributor

minggo commented Sep 29, 2019

I tested on iPhone11 with iOS13.

@minggo
Copy link
Contributor

minggo commented Sep 29, 2019

I tried iPhone8 with iOS 13, can reproduce it.

@lxhhuangjin
Copy link
Author

I tested on iPhone11 with iOS13.

I tried the code of @wandeli and the problem has been resolved. But when i close the IME and touch screen where do not have textfield, the IME opened. This is another problem. But i think his code is a correct direction for this problem.

@minggo
Copy link
Contributor

minggo commented Sep 29, 2019

It is because engine can not receive touches end event, but i don't know why. If don't modify markedTextRange , then can just input a character a time.

@lxhhuangjin
Copy link
Author

It is because engine can not receive touches end event, but i don't know why. If don't modify markedTextRange , then can just input a character a time.

Maybe i should modify setMarkedText and concat string by myself in iOS13.

@wandeli
Copy link

wandeli commented Oct 9, 2019

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent )event
    {
    for (UIGestureRecognizer
    ges in [self gestureRecognizers])
    {
    [self removeGestureRecognizer:ges];
    }

add this can receive touches end even

@Kafka2
Copy link

Kafka2 commented Oct 9, 2019

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent )event
    {
    for (UIGestureRecognizer
    ges in [self gestureRecognizers])
    {
    [self removeGestureRecognizer:ges];
    }

add this can receive touches end even

and also add this in touches cancel event.

But I don't know why UIKit adds a sort of GestureRecognizers in iOS 13+

@minggo
Copy link
Contributor

minggo commented Oct 10, 2019

@wandeli it may slow down the performance of touch events. And it is strange that iPhone11 with iOS 13 doesn't have problem.

@Kafka2
Copy link

Kafka2 commented Oct 10, 2019

@wandeli it may slow down the performance of touch events. And it is strange that iPhone11 with iOS 13 doesn't have problem.

I reproduced the problem in iPhone11 with iOS 13.1.2 using system input method.

@minggo
Copy link
Contributor

minggo commented Oct 10, 2019

My iPhone 11 is updated to iOS 13.1.2, and there is not problem. I don't use system input method, use 搜狗.

@minggo
Copy link
Contributor

minggo commented Oct 10, 2019

I uses 搜狗 instead of system input method, it works on iPhone 8(13.0) too. So the problem exists in system input method.

@lxhhuangjin
Copy link
Author

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent )event
    {
    for (UIGestureRecognizer
    ges in [self gestureRecognizers])
    {
    [self removeGestureRecognizer:ges];
    }

add this can receive touches end even

and also add this in touches cancel event.

But I don't know why UIKit adds a sort of GestureRecognizers in iOS 13+

Maybe related to QuickPath in iOS 13+. This is the new function in iOS 13+ and seems like related to GestureRecognizers.

@huachangmiao
Copy link
Contributor

@minggo
Is there any progress?

@pandaGames
Copy link

same issue.use system input method can reproduce the problem.but editbox works fine in iOS13.

@minggo
Copy link
Contributor

minggo commented Oct 12, 2019

@huachangmiao sorry, there is not progress. I will continue to fix it.
@pandaGames EditBox uses UIKit component.

@wordes
Copy link

wordes commented Oct 14, 2019

@minggo
Is there any progress?

@huangwei1024
Copy link

we also encounter the same problem, in cocos2dx 3.X and ios 13.1

@EricDDK
Copy link
Contributor

EricDDK commented Oct 15, 2019

I change 2 functions and everything is OK.

static UITextRange * s_textRange = [[UITextRange alloc] init];

- (UITextRange *)markedTextRange;
{
    CCLOG("markedTextRange");
    if (nil != markedText_) {
        return s_textRange;
    }
    return nil; // Nil if no marked text.
}
- (NSString *)textInRange:(UITextRange *)range;
{
    CCLOG("textInRange");
    if (nil != markedText_) {
        return markedText_;
    }
    return @"";
}

@Kafka2
Copy link

Kafka2 commented Oct 15, 2019

@EricDDK it triggers the same issue related to GestureRecognizors.

@Guy-kun
Copy link
Contributor

Guy-kun commented Oct 23, 2019 via email

@minggo
Copy link
Contributor

minggo commented Oct 24, 2019

@Guy-kun sorry, i have not idea. I think you should modify it according the PR.

@minggo
Copy link
Contributor

minggo commented Oct 24, 2019

@Guy-kun yep, it can not work, i think i made some mistake in refactoring codes. I sent #20232 to fix it based on #20209.

@minggo minggo closed this as completed Oct 24, 2019
@Guy-kun
Copy link
Contributor

Guy-kun commented Oct 24, 2019

Appears to be working from some quick tests!
We'll QA properly and report if there's any further issues

@Guy-kun
Copy link
Contributor

Guy-kun commented Oct 28, 2019

This appears to still have an issue with:
tapping outside keyboard to close either keyboard (app stops receiving touches)
as previously.

It seems to be fairly inconsistent and repeatedly tapping outside of the keyboard to close it (2 or 3 times) will make touches stop responding correctly in-app. The view may possibly be getting offset/moved incorrectly as this seems inconsistent?

This happens even with the standard english keyboard after the PR.

@Guy-kun
Copy link
Contributor

Guy-kun commented Oct 31, 2019

@minggo any chance of taking a look at this again?

@minggo
Copy link
Contributor

minggo commented Nov 1, 2019

How to reproduce it? Could you please describe it in more detail?

@minggo
Copy link
Contributor

minggo commented Nov 1, 2019

I tested text-input in cpp-tests:

  • click screen to pop up keyboard
  • click outside of keyboard to close it
  • repeat above operations many times

App can response touch events correctly. If you don't mind, would you please use v3 latest codes to test?

@huangwei1024
Copy link

I merged #20232 #20209 #20250 in my proj.

you need add a background layer. it will hide widget when you touch the background.
like this

		local blackLayer = ccui.Layout:create()
		blackLayer:setContentSize(display.sizeInView)
		blackLayer:setBackGroundColorType(1)
		blackLayer:setBackGroundColor(color)
		blackLayer:setOpacity(0)
		blackLayer:setTouchEnabled(true)
		blackLayer:setPosition(cc.p(display.board_left, 0))
		bind.click(self, blackLayer, {method = function()
			self:onClose()
		end})

#20281 was use background layer.

if you not had other layers, the problem was some touch had no effect.

@minggo
Copy link
Contributor

minggo commented Nov 4, 2019

@huangwei1024 please provide a demo to reproduce it.

@lxhhuangjin
Copy link
Author

lxhhuangjin commented Nov 4, 2019

@minggo I had tried the new code on iOS 10.3 and find a problem.When i input charactor for Chinese, no predict text appear. In addition to Chinese, i input number or English is ok. So i compare these code with the last version and find these code has been deleted.I want know why. And i add these code, the input for Chinese can be work.
- (UITextRange *)selectedTextRange; { return [[[UITextRange alloc] init] autorelease]; }

@minggo
Copy link
Contributor

minggo commented Nov 4, 2019

@lxhhuangjin as it works without it when i tested, and selected text means the text selected in a view. So i deleted it to make codes clean. The usage of UITextInput is wired in engine, indeed i don't quite understand all the protocol.

@lxhhuangjin
Copy link
Author

@minggo You can reproduce the problem i described on iOS10.

@lxhhuangjin
Copy link
Author

@minggo Another problem. When i open keyboard by EditBox, the keyboard can not be closed when i click the screen out of the keyboard. The function named "onUIKeyboardNotication" need belong with CCEAGLView in my opinion.

@minggo
Copy link
Contributor

minggo commented Nov 4, 2019

@minggo Another problem. When i open keyboard by EditBox, the keyboard can not be closed when i click the screen out of the keyboard. The function named "onUIKeyboardNotication" need belong with CCEAGLView in my opinion.

I think it is fixed in #20250.

@lxhhuangjin
Copy link
Author

@minggo You can see the code in CCUIEditBoxIOS.mm.
- (void)openKeyboard { auto view = cocos2d::Director::getInstance()->getOpenGLView(); CCEAGLView *eaglview = (CCEAGLView *)view->getEAGLView(); [eaglview addSubview:self.textInput]; [self.textInput becomeFirstResponder]; }
The InputView was add to EAGLView. But EAGLView do not listen to the event of didMoveToWindow.

@Guy-kun
Copy link
Contributor

Guy-kun commented Nov 4, 2019

I'm having problems setting up a latest test project due to my current cocos environment/version and can't finish it today but I'm aiming to try the following code where I presume touches to the button will stop working/be in an incorrect position?

    auto textField = ui::TextField::create();
    textField->setPosition(Vec2(this->getContentSize().width/2 , this->getContentSize().height/2 - 50));
    this->addChild(textField);
    
    auto testButton = ui::Button::create("HelloWorld.png");
    testButton->setTitleText("Tap");
    
    this->addChild(testButton);

    testButton->setPosition(this->getContentSize()/2);
              
    testButton->addTouchEventListener([&,testButton](Ref* pSender, cocos2d::ui::Widget::TouchEventType type) {
        if (type == cocos2d::ui::Widget::TouchEventType::ENDED)
        {
            testButton->setOpacity(0);
            testButton->runAction(FadeTo::create(1, 255));
            
        }
    });

@minggo
Copy link
Contributor

minggo commented Nov 5, 2019

The InputView was add to EAGLView. But EAGLView do not listen to the event of didMoveToWindow.

@lxhhuangjin CCInputView do it. And i will add selectedTextRange back.

@minggo
Copy link
Contributor

minggo commented Nov 5, 2019

@lxhhuangjin ok, i got your idea, you mean the function should be added in CCEAGLView, yep, i think you are right.

@lxhhuangjin
Copy link
Author

@minggo I am glad to see you know what i mean. Ok, waiting for your update of the code.

@minggo
Copy link
Contributor

minggo commented Nov 5, 2019

I sent #20294, hope it fixes all issues. I tested on iPhone11(iOS 13.1.2), iPhone8(iOS 13.1.3) and iPhone5s(iOS 12.4).

@Guy-kun
Copy link
Contributor

Guy-kun commented Nov 6, 2019

It's extremely hard to see if this is fixed as we use an older version of v3 to which I can't apply patches directly due to differences...
Is there any reason for sending 4 PRs for this fix rather than updating a single one?? it makes it so much harder to manage manually merging them in...

To reiterate, this issue now is affected by 4 PRs
#20232 #20209 #20250 #20294

@Guy-kun
Copy link
Contributor

Guy-kun commented Nov 6, 2019

I've reproduced the cause of the issue I'm having @minggo
This also happens on latest v3 in a test project using the simple textview code I sent previously.

It appears that when tapping to dismiss the keyboard outside of it's bounds CCEAGLView::touchesBegan is called, but there are no subsequent calls touchesEnded or touchesCancelled

This results in CCGLView not decrementing unusedIndex and therefore tracking all subsequent touches as +1 in touchID. This seems like a real issue that needs fixing as it breaks touch IDs
(Our UI was customized to reject touches >1 in order to prevent accidental multitouch misfires resulting in it 'not working' anymore) Repeats of these steps will repeatedly increment the current touchID of new touches

I can't find any cause for touchesEnded not being called so I'll have to leave it as a report here unfortunately that needs fixing.

@minggo
Copy link
Contributor

minggo commented Nov 7, 2019

@Guy-kun sorry about so many PRs, it is because i thought it is fixed as i tested myself. Maybe the test case i used is not good enough to reproduce the issue. And i don't think you need to apply PR one by one, it only affects CCEAGLview and adding CCInputVie, you can just replace these two files to test.

About the touch end missing issue i will take a look, but i am not sure if i can fix it if it has the issue. Maybe you can create a new issue as the issue is not the same as this one.

@minggo
Copy link
Contributor

minggo commented Nov 7, 2019

@Guy-kun i sent #20303 to fix it. This time i will not merge the PR until some of you confirm that the issue is resolved.

@Guy-kun
Copy link
Contributor

Guy-kun commented Nov 7, 2019

Thanks very much, I've left a comment that we'll test it more but it seems to be good at a quick check.

As for why the 4x merges were hard, as stated before we are using an earlier v3 of cocos and can't apply a patch on top of CCEAGLView due to possibly incompatibility as it does not match this 3.17 codebase...
It seems to be resolved though for now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests