Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTL 支持 #22

Closed
kakarrot opened this issue Jun 2, 2022 · 4 comments
Closed

RTL 支持 #22

kakarrot opened this issue Jun 2, 2022 · 4 comments

Comments

@kakarrot
Copy link

kakarrot commented Jun 2, 2022

当布局切换成 RTL 以后,LEFT 和 RIGHT 会调换位置,所以在布局上已经没什么问题,但实际上此时 rightMenu 在左侧,leftMenu在右侧,故:openXXXMenu() 和 closeXXXMenu() 操作的是相反的 menu, 只需要添加一行判断,如果是 RTL 布局就判断 activeMenu 是否是相反的 menu 即可

private val isRtl by lazy {
        TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL
}
fun openLeftMenu(animate: Boolean = true) {
        activeMenu = if(isRtl) rightMenu else leftMenu
        openActiveMenu(animate)
}

同理:

fun isLeftMenuOpened(): Boolean {
        val activeMenu = activeMenu ?: return false
        return activeMenu == (if(isRtl) rightMenu else leftMenu) && openState and FLAG_IS_OPENED == FLAG_IS_OPENED
}

fun isRightMenuOpened(): Boolean {
        val activeMenu = activeMenu ?: return false
        return activeMenu == (if(isRtl) leftMenu else rightMenu) && openState and FLAG_IS_OPENED == FLAG_IS_OPENED
 }
@aitsuki
Copy link
Owner

aitsuki commented Jun 2, 2022

好的,我稍微试了一下发现改RTL后还会有其他小问题,例如parallax的顺序错了。我找时间一并修复后再发个新版本吧

@aitsuki
Copy link
Owner

aitsuki commented Jun 2, 2022

我发现切换RTL布局后,所有类型的菜单都出现了问题,原因是Designer的onInit方法的回调时机有误。
目前已修复这个Bug 64535f1

另外,我暂时不会修改OpenLeftMenu和OpenRightMenu这几个方法,我不确定它们的行为是否真的是错的,毕竟阿拉伯人的左边和我们的左边是同一个概念,只是Android为了适配RTL把我们弄混乱了。

你可能需要的是OpenStartMenu和OpenEndMenu这几个方法。

@kakarrot
Copy link
Author

kakarrot commented Jun 6, 2022

嗯,确实如此,openLeftMenu()openRightMenu() 的方法可以不变,新增加 openStartMenuopenEndMenu() 更好

@aitsuki
Copy link
Owner

aitsuki commented Jun 7, 2022

https://github.com/aitsuki/SwipeMenuRecyclerView/releases/tag/2.1.4 已支持RTL(未经过严格测试,出问题再重新打开此Issue吧)

@aitsuki aitsuki closed this as completed Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants