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

[Android] Fix and reimplement user input in EditText control #2302

Merged
merged 3 commits into from
Jun 8, 2024

Conversation

Basewq
Copy link
Contributor

@Basewq Basewq commented Jun 2, 2024

PR Details

This pull reimplements showing the Android EditText control when a user taps Stride's EditText.

Technical details are:
Removed Game.axml - This was what should have been loaded, however in the transition to SDL, xen2 probably encountered some issues and just skipped over it.
Based on ancient times when it worked, the native EditText control and the rendering view sat together with a common container, however now SDL sits as the main view and would be a little hacky to try to jimmy it into the Game.axml layout.
This implementation avoids this completing by making the native EditText control live on its own layout and is displayed as a PopupWindow. This also has the benefit of not shifting up the rendering view when the soft input (on-screen keyboard) appears.

Old implementation:
Emu_EditText_Old

New implementation (left):
Emu_EditText_New

New changes include adding an OK button close the popup, however the player can also just tap anywhere on the screen to close it.
There's quirk where selection/caret position from the native control is reflected back to Stride's control - this was in the original behavior and is still retained here. Personally I think Stride's control should disable rendering caret/selection in this case since the player should be looking at the native control. This could be a future enhancement.
Another change is that when the keyboard shows up, it'll immediate select all the text. The original behavior would just set the caret at the beginning of the text - in my opinion this is the least logical expectation of a user. Probably another enhancement would be to change the behavior of what the initial state should be, eg. SelectAll | CaretAtBegining | CaretAtEnd

Due to SDL, Stride is running on a separate thread from Android UI thread, so most Android EditText method calls are done through its Post method, which ensures it's enqueue to call on the UI thread.

Resource.Designer.cs can now be removed. As of .NET8, the Xamarin build system will generate it all at once in the developer's project.

The stride_popup_edittext.xml lives in the Platforms\Android\ folder.
At some point in the future I think all (or most?) platform specific code should be placed in Platforms\[PLATFORM]\, as this actually how .NET MAUI prefers organizing code/assets.


There is a breaking change to GameContextAndroid:

  • GameContextAndroid constructor changed.
  • EditTextLayout field removed.
    However it is highly unlikely users ever touched these as they were only really used for Stride's internal setup.

Changed the Android templates so some of the AndroidManifest settings can be moved to [Activity] in GAMENAMEActivity.cs
Note that in the 'New implementation' image above, the left using the original/default theme Theme.NoTitleBar.Fullscreen
I was tempted to change this to Theme.Material.Light.NoActionBar.Fullscreen (as seen in the right image) to make it look a bit more modern. This theme is only available on API 21 and above (which is already the project's minimum API level).
I have withheld this temptation since this is changeable by the developer in their own project, but just pointing out the option is there.


While I have tested this as much as I could, I believe we should make an alpha build to properly test how it behaves as a proper nuget package, as I cannot replicate the entire cross-platform nuget build/packaging that the official system has.
This also minimizes the 'it works on my machine' excuse.

A 'working' 4.2 Android project can be found here
https://github.com/Basewq/BasewqStrideAndroidTests/tree/main/AndStrideGame

Related Issue

Fixes #2289

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

Basewq added 2 commits June 3, 2024 11:43
… applicable and remove duplicate Theme setting

Remove extra whitespaces in Android templates
@Basewq Basewq force-pushed the android_edittext_fix branch from 1c5503f to 78dc938 Compare June 2, 2024 23:44
@Basewq Basewq marked this pull request as ready for review June 3, 2024 00:52
@Eideren
Copy link
Collaborator

Eideren commented Jun 7, 2024

…where Stride deactivates the control before the Android Post action executes
@Basewq
Copy link
Contributor Author

Basewq commented Jun 8, 2024

Thanks for the new package/build, the main thing I was checking for is the stride_popup_edittext.xml to stay in the .aar file and not spill into the other platform's and thankfully it was ok.

I've had to add a new commit to lock a bunch of execution, as it turns out being on the Android UI thread is not safe as editText can be unset by the time it executes due to doing weird swiping actions on the phone.

@Eideren Eideren merged commit 47375e3 into stride3d:master Jun 8, 2024
12 of 13 checks passed
@Eideren
Copy link
Collaborator

Eideren commented Jun 8, 2024

Thanks !

@Basewq Basewq deleted the android_edittext_fix branch June 9, 2024 00:58
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

Successfully merging this pull request may close these issues.

Android crashes when clicking into EditText UI control
2 participants