Compose之RTL布局

96 阅读1分钟

image.png

  1. Compose的预览中可以使用locale=“ar”,如TopBarPreview1()

  2. 代码中可以使用CompositionLocalProvider(),如TopBarPreview2()

  3. RTL布局时,icon方向是反的,此时可以

  • 新建drawable-ldrtl等文件夹,放入翻转后的icon

  • 自定义Modifier,翻转图片,如下图的TopBarPreview1()/TopBarPreview2()

      fun Modifier.rtl(): Modifier = composed {
          val layoutDirection = LocalLayoutDirection.current
          scale(
              scale = if (layoutDirection == LayoutDirection.Rtl) {
                  -1f
              } else {
                  1f
              }
          )
      }
    

image.png