Resolved Context menu options gone in 20.7.23


Ankka

Members
Jun 8, 2020
28
15
Android allows developers to add custom actions to the context menu (ie. the text selection menu) in their apps (see screenshot below for example, Kuroba is the app). Such actions weren't accessible on MIUI 10 or 11 though since Xiaomi replaces the stock Android text selection menu with their own implementation. An app I use frequently has custom actions in the text selection menu which is why I was very pleasantly surprised to see that MIUI 12 had added support for them. But then I flashed 20.7.23 and noticed these actions were gone again.

Screenshot_2020-07-24-19-51-17-906_com.github.adamantcheese.chan.dev.png
 

Igor Eisberg

Developer
Staff member
Oct 6, 2016
6,164
322
You have a point, I do remember custom actions being supported on MIUI in the past.
In fact, Kuroba's source code explicitly mentions this piece of code, which will definitely help me in tracking down this issue.
Code:
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    quoteMenuItem = menu.add(Menu.NONE, R.id.post_selection_action_quote, 0, R.string.post_quote);
    webSearchItem = menu.add(Menu.NONE, R.id.post_selection_action_search, 1, R.string.post_web_search);
    return true;
}
 

qduborper

Members
Dec 9, 2020
4
3
Hello @Igor Eisberg @Ankka ,

I face a similar issue is on a react native application using react-native-selectable-text plugin:

you can see the plugin implementation here to customise selection text menu:

this seems not working on xiaomi / IMUI phones, whereas it works on other android phones. Do you know why setCustomSelectionActionModeCallback and onPrepareActionMode are not applied here ? This would help many developers facing the same problem

Best regards
 

qduborper

Members
Dec 9, 2020
4
3
Thanks for your reply. I added a sample app here which uses the same implementation as the react native plugin for setting custom action on a textView:

so see below a screenshot on huawei phone display custom action:

33286


Maybe is it due to miui 11 version ? Users who face this issue are on miui 11. If it's possible to know if miui 12 will fix this it's good to know.

Best regards
 
Last edited:

Igor Eisberg

Developer
Staff member
Oct 6, 2016
6,164
322
MIUI 11? It's no longer supported.
Either way, if you people are using an official MIUI ROM, then that might be the problem. We can solve stuff on our end, but we're just a custom ROM, most users stick to official ROMs, where we have no influence.
 

qduborper

Members
Dec 9, 2020
4
3
ok thank you for your answer. So do you know if these custom actions to the context menu support is part of the official MIUI 12 version, or is it part of the custom ROM you deliver ? It's to understand if official releases fixed this issue, unfortunately I don't see elsewhere so much information about this
 

Igor Eisberg

Developer
Staff member
Oct 6, 2016
6,164
322
ok thank you for your answer. So do you know if these custom actions to the context menu support is part of the official MIUI 12 version, or is it part of the custom ROM you deliver ? It's to understand if official releases fixed this issue, unfortunately I don't see elsewhere so much information about this
I don't know, I don't use official ROMs.
 

Ankka

Members
Jun 8, 2020
28
15
Hello @Igor Eisberg,
I noticed that the text selection menu options are gone again on Android 11 based weeklies (20.12.29/30, 21.1.6).

33890
 

Attachments

  • IMG_20210109_035547.jpg
    IMG_20210109_035547.jpg
    57.8 KB · Views: 74

Igor Eisberg

Developer
Staff member
Oct 6, 2016
6,164
322
Hello @Igor Eisberg,
I noticed that the text selection menu options are gone again on Android 11 based weeklies (20.12.29/30, 21.1.6).

View attachment 33890
Yep, unfortunately Xiaomi's Android 11 implementation for ActionPopupWindow removed any possibility of support for custom actions. Our patching still works for Android 10, where the required code still exists. This is a game over for custom actions. It's up to Xiaomi to fix this nonsense.
 
  • Like
Reactions: Ankka

Igor Eisberg

Developer
Staff member
Oct 6, 2016
6,164
322
Damn, sucks to hear that. I guess I will go complain to Xiaomi now. Thanks for your reply.
With some hard work restoring the code Xiaomi removed, I managed to get the custom actions back, and to work better than they used to work: custom actions were shown on initial selection and when releasing the left selection modifier, but not when releasing the right selection modifier, now I managed to make them work on both.

Thanks for your reply. I added a sample app here which uses the same implementation as the react native plugin for setting custom action on a textView:

so see below a screenshot on huawei phone display custom action:

View attachment 33286

Maybe is it due to miui 11 version ? Users who face this issue are on miui 11. If it's possible to know if miui 12 will fix this it's good to know.

Best regards
The investigation I performed while fixing this issue again taught me a few things:
Xiaomi disables AOSP's text selection popup and replaced it with their own implementation, hence the difference in behavior.
Even when I removed a piece of code that prevented the custom actions from showing, they would still only show up if they were added in onCreateActionMode, which is non-standard, as Google specifically said that the menu should be modified in onPrepareActionMode.
Apps like Kuroba use onCreateActionMode to add custom items, hence the items were showing.
Your test app uses onPrepareActionMode, according to Google documentation, but Xiaomi's implementation never calls onPrepareActionMode for custom menus. This is another issue I sorted out in my new patch, and onPrepareActionMode is properly called directly after onCreateActionMode (only if onCreateActionMode returns true, of course), according to Google's documented lifecycle for this action mode: