Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b93911f2 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Improve resolution of inherited layout direction

allow to resolve it even more lazily: if resolution is asked then do it
only if possible (the View needs to have a parent that can also do its
resolution)

Change-Id: I8e808f0ef392521e59b27b82f86e9058f20af9ba
parent 3a4832aa
Loading
Loading
Loading
Loading
+12 −9
Original line number Original line Diff line number Diff line
@@ -5704,7 +5704,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL")
        @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL")
    })
    })
    public int getResolvedLayoutDirection() {
    public int getResolvedLayoutDirection() {
        // The layout diretion will be resolved only if needed
        // The layout direction will be resolved only if needed
        if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) != LAYOUT_DIRECTION_RESOLVED) {
        if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) != LAYOUT_DIRECTION_RESOLVED) {
            resolveLayoutDirection();
            resolveLayoutDirection();
        }
        }
@@ -11466,16 +11466,19 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // Set resolved depending on layout direction
            // Set resolved depending on layout direction
            switch (getLayoutDirection()) {
            switch (getLayoutDirection()) {
                case LAYOUT_DIRECTION_INHERIT:
                case LAYOUT_DIRECTION_INHERIT:
                    // If this is root view, no need to look at parent's layout dir.
                    // We cannot resolve yet. LTR is by default and let the resolution happen again
                    if (canResolveLayoutDirection()) {
                    // later to get the correct resolved value
                    if (!canResolveLayoutDirection()) return;
                    ViewGroup viewGroup = ((ViewGroup) mParent);
                    ViewGroup viewGroup = ((ViewGroup) mParent);
                    // We cannot resolve yet on the parent too. LTR is by default and let the
                    // resolution happen again later
                    if (!viewGroup.canResolveLayoutDirection()) return;
                    if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                    if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                        mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
                        mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
                    }
                    }
                    } else {
                        // Nothing to do, LTR by default
                    }
                    break;
                    break;
                case LAYOUT_DIRECTION_RTL:
                case LAYOUT_DIRECTION_RTL:
                    mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;
                    mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL;