Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Native TextField events numDeleted and newCharacters fail on Android
Started by Divergent Monkey Jul 15 2019 01:54 PM

- - - - -
14 replies to this topic
android native events
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

The events numDeleted and newCharacters do not behave as described in the docs on Android (4.3). Please see the attached demo project for a working example. When run, you can see that

 

  • newCharacters returns ALL characters, not just the newly typed.
  • numDeleted returns string length -1 every time a new character is entered (i.e. not deleted)

When run on iOS, all works acording to the docs. Is this a bug?



[TOPIC: post.html]
#2

carloscosta

[GLOBAL: userInfoPane.html]
carloscosta
  • Contributor

  • 649 posts
  • Corona SDK

who cares about android 4.3? just make app to run only from android 5+.

 

why not to make yourself a counter? is a 5m process to make both variables running.



[TOPIC: post.html]
#3

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

@carloscosta: first: in many parts of the world, people run their apps on much older devices than both you and I are used to. I want to make sure my apps work for them too. Besides, I just tested it on Android 8 and it does not work there either.

 

Second: I know there are workarounds but my question was whether this was a bug or not.



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,900 posts
  • Enterprise

There does appear to be something mysterious going on with event.numDeleted. It goes up each time from 0 to strlen -1 even on my Android 9 nexus tablet. 

 

But you're overthinking the problem if the goal is to get the currentText. Just grab event.text during the editing event, but after submitted you won't have that any more, but will have event.target.text during the submitted phase to get the actual field results.

 

Can you provide a valid use case for needed numDeleted given that you can get the current contents of the text field without it?

 

Most people are not using this, so it's going to be a low priority fix. 

 

Rob



[TOPIC: post.html]
#5

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

@Rob:

My use case is the following: I am building an app which interacts with the user via the keyboard only. For reasons of visual appearance, I have hiden the native text field outside of the screen and I display the text (that the user enters) as a TextObject in a custom "speech bubble"instead. As the user types the text, character by character is added to the TextObject in the speech bubble.

 

It would be easy to just copy event.text as the user enters the characters, but the "iOS smart punctuation" screws up words like "I'm" so that the TextObject becomes "Im" since the "smart" apostrophe is not recognized as a normal apostrophe. By using newCharacters I can analyse each new character and replace the "smart" apostrophe if there is one:

if (newCharacter == "'") then
    currentText = currentText .. "'"
else
    currentText = currentText .. newCharacter
end

(I know that the code above looks strange but it actually works, the smart apostrophe is replaced by a regular one).

 

So, the situation is that newCharacters does not work on Android and event.text does not always work on iOS (due to the smart punctuation) when copied to TextObject.text. A possible workaround could be to analyse the last character of event.text instead but I will have to confirm that after some further analysis.



[TOPIC: post.html]
#6

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

@Rob:

Just remembered, I actually created a post about the problem with the iOS smart punctuation and you responded:

 

https://forums.coronalabs.com/topic/72375-superweird-single-quote-error-with-native-textfield-on-ios/

 

This means that there is currently NO possibility to take the content of a TextField and making a TextObject out of it in a way that will always work as expected...



[TOPIC: post.html]
#7

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

If your read the post I referred to, you can see that I actually filed a bug report in April 2018 for the problem with the smart punctuation. Unfortunately, filing a bug report with Corona is like sending stuff into a black hole, you never hear from it again...

 

Unless there is a workaround that I do not know of, this together with the Android native text bug are now a showstopper.



[TOPIC: post.html]
#8

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

There seems to be a way to disable iOS smart punctuation by setting the iOS property smartQuotesType to UITextSmartQuotesTypeNo. 

 

https://pspdfkit.com/blog/2018/ios-11-smart-punctuation/

 

See the section "Replacing Smart Quotes with Straight Quotes" at the end. Would this be possible to set in Corona somehow? If so, that would at least take care of the iOS part of the problem.



[TOPIC: post.html]
#9

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,900 posts
  • Enterprise

This is the kind of bug that will likely never rise to the level that we will have time to address or fix. You're trying to use native.newTextField in a way it was not designed for (albeit a popular desired feature). We have to balance this against being able to publish your game to Apple and Google. We have two rapidly approaching deadlines from Google to meet.

 

Our team is absolutely swamped right now and I can assign this to an engineer, but the chances of it getting worked on is very unlikely.

 

Back in January, we made the source code open source, hoping the community would get more involved and this is a good feature for a community developer to take up and work on.

 

Rob



[TOPIC: post.html]
#10

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

Ok, I understand. I created an issue for this on the GitHub page of Corona, is that the correct way to raise this to the community?



[TOPIC: post.html]
#11

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,900 posts
  • Enterprise

Yes



[TOPIC: post.html]
#12

carloscosta

[GLOBAL: userInfoPane.html]
carloscosta
  • Contributor

  • 649 posts
  • Corona SDK

 

@carloscosta: first: in many parts of the world, people run their apps on much older devices than both you and I are used to. I want to make sure my apps work for them too. Besides, I just tested it on Android 8 and it does not work there either.

 

Second: I know there are workarounds but my question was whether this was a bug or not.

 

Android market share with version less than 4.4 is less than 5%. And that's all versions combined. And this numbers will go down with time ofc.

If the problem is with android 8 also, that's new data that was not mention before. But I don't spend time optimizing my code for 5% of market share. I prefer to spend my time, providing a much better experience to the rest of the 95%. If I can do it for the 100%, ofc I will, but in smartphones, that's probably impossible. There's to many makers, variables and screen sizes to make them all happy.

 

Second: you knew already it was a bug, you just needed the confirmation. I gave you a simple solution for a problem you already knew and corona will not take care, at least for a long time.



[TOPIC: post.html]
#13

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

@carloscosta:

No problems, thanks!  :)



[TOPIC: post.html]
#14

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,900 posts
  • Enterprise

The event.numDeleted isn't correct on Android 7 either so it's definitely a different behavior on Android than the documentation implies. It's something that needs looked at.

 

Rob



[TOPIC: post.html]
#15

Divergent Monkey

[GLOBAL: userInfoPane.html]
Divergent Monkey
  • Contributor

  • 328 posts
  • Corona SDK

I understand that this has a low prio but I am thankful that you will look at it eventually. As previously mentioned, there is also the other bug with the incorrect interpretation of the iOS "smart punctuation" correctly. Maybe that wil also be looked at eventually (bug report filed a year ago).

 

Anyway, I have found a workaround so I am not stuck anymore...  :)




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: android, native, events