-
Notifications
You must be signed in to change notification settings - Fork 82
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
frontend/android: check if webview can go back or close the app #2701
base: master
Are you sure you want to change the base?
frontend/android: check if webview can go back or close the app #2701
Conversation
20ca1f2
to
81f8401
Compare
7702edf
to
17f8920
Compare
16a9db7
to
8d94eb2
Compare
8d94eb2
to
21fde51
Compare
Would be good to describe the behavior more clearly. When/where does a navigation add to the navigation history? A way to unit test this stuff would be very nice, to document the navigation behavior clearly. I also wonder how robust this is - can a change like #2524 change this behavior? Again some sort of automated tests would be very very good to have for this. |
To be explicit, you want to test I guess that would be very nice. I have no idea what that takes, would it test with a real webview with our production bundled.js and simulating user clicking in react UI and then simulating webview.goBack() and testing if the URI is correct? Sounds to me more like integration / e2e test, rather than unit test? As far as I see we don't have any java test or maybe I am blind. Also I am afraid that I have no idea how to setup something like this.
I don't see any reason why it shouldn't work, but I will test this branch on top of #2524 . I believe worst case
This is a good question. There is |
21fde51
to
1e5b09b
Compare
rebased |
// See the following for details about task and activity stacks: | ||
// https://developer.android.com/guide/components/activities/tasks-and-back-stack | ||
@Override | ||
public void onBackPressed() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was deprecated in API level 33.
API level 33.
Use OnBackInvokedCallback or androidx.activity.OnBackPressedCallback to handle back navigation instead.
https://developer.android.com/reference/android/app/Activity#onBackPressed()
1e5b09b
to
772821e
Compare
772821e
to
9686201
Compare
The tests don't have to be inside Android/Java, you can assume it works like a Chromium browser. It would just be very good if we had a good list of tests (manual tests in the worst case, automated would be best) that show that history-back goes to the expected place. Worse than a back button that closes the app is one that does not work as expected 😄 |
unfortunately it already does not work as expected. I expect that it does history back, but it always just goes back to account summary. I am not sure why, and am not sure how to remote debug right-now. In webdev history back works as expected.. It would be very nice if both behave the same, need to investigate what exactly is happending in the webview when we call goBack() (or the js version |
This should replace native Android back behavior with either going back in the webview history or closing the app. In theory the react-router pushes history entries to the webview navigation history, as soon as the user clicks a Link or navigate is called. The navigate function can also be called with replace option so that it does not add to the history. This is using the native goBack method but it seems that the app only goes back to account summary. In theory this should behave the same as native browser back. It is not clear why it jumps to the beginning. So this could probably be improved, but seems already useful with just going back to the account summary. On the account summary it cannot go back any further so it will trigger the old do-you-want-to-quit alert. Replaced deprecated onBackPressed override.
9686201
to
7eeefff
Compare
The previous commit added a condition webview.canGoBack() and then uses goBack() if the webview can go back in history. This does not behave the same as native browser back in webdev. The webview loads with loadDataWithBaseURL, where the 4th argument is historyUrl which is null. Introduced in: 3b62772 This commit uses same base url to initialize historyUrl.
testing if initializing with correct historyUrl changes the goBack behavior. |
47cecb1
to
b5ddc82
Compare
fa7639e
to
c3bd59e
Compare
520aea4
to
1a70cce
Compare
Alert component exposes a function to be called from anywhere. This is a bit a hack and if called multiple times, last alerts are lost. Changed to check if alert is already active and append new messages to the same alert.
seems sd there can be similar issues when using history back from a webview that was loaded by loadDataWithBaseURL. This is wild guess https://stackoverflow.com/questions/3574674/android-webviews-method-goback-shows-a-blank-page
trying recommendation from one of the answers from https://stackoverflow.com/questions/8974102/android-blank-screen-on-onback-in-a-loaddatawithbaseurl?noredirect=1&lq=1
test to check if loadDataWithBaseURL with shiftcrypto.ch origin might cause history to go back to "https://shiftcrypto.ch/" introduced in 3b62772
1a70cce
to
1ef754b
Compare
This should replace native Android back behavior with either going
back in the webview history or closing the app.
In theory the react-router pushes history entries to the webview
navigation history, as soon as the user clicks a Link or navigate
is called. The navigate function can also be called with replace
option so that it does not add to the history.
This is using the native goBack method but it seems that the app
only goes back to account summary. In theory this should behave
the same as native browser back. It is not clear why it jumps to
the beginning.
So this could probably be improved, but seems already useful with
just going back to the account summary.
On the account summary it cannot go back any further so it will
trigger the old do-you-want-to-quit alert.
Replaced deprecated onBackPressed override.