Mozilla EngineView Geckoview 渲染元素隐藏在工具栏后面

如何解决Mozilla EngineView Geckoview 渲染元素隐藏在工具栏后面

使用 android mozilla mobile android 组件构建浏览器。我有一个动态顶部工具栏和一个动态底部工具栏,覆盖 mozilla.components.concept.engine.EngineView(在幕后使用 Geckoview)。工具栏在引擎视图滚动时显示/隐藏。

问题是网页元素隐藏在本机工具栏后面。例如,youtube.com 主页具有基于 html 的动态顶部和底部工具栏,它们隐藏在我的本机工具栏后面。

mozilla.components.feature.session.behavior.EngineViewBottomBehavior 类更改操作方法告诉引擎视图在哪里放置元素。如果我的应用程序中有一个工具栏,这会起作用。例如,如果我只有一个顶部工具栏,则 topToolbarChangedAction() 设置垂直剪辑,而 youtube.com html 顶部工具栏位于我的本机工具栏下方。但是,当我有 2 个工具栏(底部和顶部)需要同时定位顶端和底端的 html 元素时,我不知道如何解决。下面是来自 mozilla 行为类的一段代码,它被调用如下

(getSwipeRefreshLayout().layoutParams as CoordinatorLayout.LayoutParams).behavior =
                EngineViewbrowserToolbarBehavior(
                    context,null,getSwipeRefreshLayout(),toolbarHeight,toolbarPosition
                )

https://github.com/mozilla-mobile/android-components/blob/master/components/feature/session/src/main/java/mozilla/components/feature/session/behavior/EngineViewBrowserToolbarBehavior.kt

  /**
 * A [CoordinatorLayout.Behavior] implementation that allows the [EngineView] to automatically
 * size itself in relation to the Y translation of the [browserToolbar].
 *
 * This is useful for dynamic [browserToolbar]s ensuring the web content is displayed immediately
 * below / above the toolbar even when that is animated.
 *
 * @param context [Context] used for varIoUs Android interactions
 * @param attrs XML set attributes configuring this
 * @param engineViewParent [nestedScrollingChild] parent of the [EngineView]
 * @param toolbarHeight size of [browserToolbar] when it is placed above the [EngineView]
 * @param whether the [browserToolbar] is placed above or below the [EngineView]
 */
class EngineViewbrowserToolbarBehavior(
    context: Context?,attrs: AttributeSet?,engineViewParent: View,toolbarHeight: Int,toolbarPosition: ToolbarPosition
) : CoordinatorLayout.Behavior<View>(context,attrs) {

    private val engineView = engineViewParent.findViewInHierarchy { it is EngineView } as EngineView?
    private var toolbarChangedAction: (Float) -> Unit?
    private val bottomToolbarChangedAction = { newToolbarTranslationY: Float ->
        engineView?.setVerticalClipping(-newToolbarTranslationY.toInt())
    }
    private val topToolbarChangedAction = { newToolbarTranslationY: Float ->
        // the top toolbar is translated upwards when collapsing-> all values received are 0 or negative
        engineView?.let {
            it.setVerticalClipping(newToolbarTranslationY.toInt())
            // Need to add the toolbarHeight to effectively place the engineView below the toolbar.
            engineViewParent.translationY = newToolbarTranslationY + toolbarHeight
        }
    }

    init {
        toolbarChangedAction = if (toolbarPosition == ToolbarPosition.TOP) {
            topToolbarChangedAction
        } else {
            bottomToolbarChangedAction
        }
    }

    @SuppressLint("LogUsage")
    override fun layoutDependsOn(parent: CoordinatorLayout,child: View,dependency: View): Boolean {
        // This package does not have access to "browserToolbar" ... so we are just checking the class name here since
        // we actually do not need anything from that class - we only need to identify the instance.
        // Right Now we do not have a component that has access to (concept/browser-toolbar and concept-engine).
        // Creating one just for this behavior is too excessive.
        if (dependency::class.java.simpleName == "browserToolbar") {
            return true
        }

        return super.layoutDependsOn(parent,child,dependency)
    }

    /**
     * Apply vertical clipping to [EngineView]. This requires [EngineViewbrowserToolbarBehavior] to be set
     * in/on the [EngineView] or its parent. Must be a direct descending child of [CoordinatorLayout].
     */
    override fun onDependentViewChanged(parent: CoordinatorLayout,dependency: View): Boolean {
        toolbarChangedAction.invoke(dependency.translationY)

        return true
    }
}

/**
 * Where the toolbar is placed on the screen.
 */
enum class ToolbarPosition {
    TOP,BottOM
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?