When child of CoordinatorLayout wants focus, show it!
The same logic is present in RecyclerView, ScrollView etc. Android really should default to this behavior for all Views with isScrollContainer = true
This commit is contained in:
parent
7dc4ccf144
commit
1bb96ef405
2 changed files with 65 additions and 2 deletions
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) Eltex ltd 2019 <eltex@eltex-co.ru>
|
||||||
|
* FocusAwareCoordinator.java is part of NewPipe.
|
||||||
|
*
|
||||||
|
* NewPipe is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* NewPipe is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.schabi.newpipe.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
|
|
||||||
|
public final class FocusAwareCoordinator extends CoordinatorLayout {
|
||||||
|
private final Rect childFocus = new Rect();
|
||||||
|
|
||||||
|
public FocusAwareCoordinator(@NonNull Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FocusAwareCoordinator(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FocusAwareCoordinator(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestChildFocus(View child, View focused) {
|
||||||
|
super.requestChildFocus(child, focused);
|
||||||
|
|
||||||
|
if (!isInTouchMode()) {
|
||||||
|
if (focused.getHeight() >= getHeight()) {
|
||||||
|
focused.getFocusedRect(childFocus);
|
||||||
|
|
||||||
|
((ViewGroup) child).offsetDescendantRectToMyCoords(focused, childFocus);
|
||||||
|
} else {
|
||||||
|
focused.getHitRect(childFocus);
|
||||||
|
|
||||||
|
((ViewGroup) child).offsetDescendantRectToMyCoords((View) focused.getParent(), childFocus);
|
||||||
|
}
|
||||||
|
|
||||||
|
requestChildRectangleOnScreen(child, childFocus, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:baselineAligned="false">
|
android:baselineAligned="false">
|
||||||
|
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
<org.schabi.newpipe.views.FocusAwareCoordinator
|
||||||
android:id="@+id/detail_main_content"
|
android:id="@+id/detail_main_content"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -526,7 +526,7 @@
|
||||||
|
|
||||||
</com.google.android.material.tabs.TabLayout>
|
</com.google.android.material.tabs.TabLayout>
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</org.schabi.newpipe.views.FocusAwareCoordinator>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/relatedStreamsLayout"
|
android:id="@+id/relatedStreamsLayout"
|
||||||
|
|
Loading…
Reference in a new issue