Search code examples
codenameone

Lightweight Popup Dialogs on iOS


After the PR https://github.com/codenameone/CodenameOne/pull/3233, I get the popupDialogs as I want them (on Android). They are ok, the text is correctly in the centre, margin and padding are as I want them.

But I have an issue with iOS. Sometimes, when the popup Dialog contains very few text, iOS calculates wrong Dimension for the Dialog. It happens only on iOS.

What I understood is that the implementation of Dialog popups on iOS is native, while on Android it's lightweight. Please correct me if I have misunderstood. Since the Android implementation works well, I would like to use it on iOS as well. That's the meaning of this RFE of mine: https://github.com/codenameone/CodenameOne/issues/3234

Anyway, I change my question: even without that RFE, can I use Lightweight Popup Dialogs also on iOS?


Solution

  • Yes but it might be a bit tricky. If you use CSS setting the popup border becomes a huge pain because of this issue.

    So you'll need to either use the designer tool and define PopupDialog to explicitly use the RoundRectBorder or you'll need to do it from code (explicitly setting this into the theme).

    A hack that might work (didn't try this) is using this code in your init(Object) instead of initFirstTheme:

    try {
        theme = Resources.openLayered(resourceFile); 
        themeProps.put("PopupDialog.derive", "Dialog");
        themeProps.put("PopupDialog.border", RoundRectBorder.create().
                cornerRadius(2f).
                shadowOpacity(60).shadowSpread(3.0f));
        themeProps.put("PopupDialog.transparency", "255");
        themeProps.put("PopupDialog.bgColor", background);
        themeProps.put("PopupDialog.padding", "4,4,4,4");
        themeProps.put("PopupDialog.padUnit", new byte[]{Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS});
        UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
        Resources.setGlobalResources(theme);
    } catch(IOException e){
        Log.e(e);
    }