mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
rtl support for divtabs (ios)
This commit is contained in:
@@ -44,6 +44,7 @@ extension DivTabs: DivBlockModeling {
|
||||
expressionResolver: expressionResolver,
|
||||
context: context
|
||||
),
|
||||
layoutDirection: context.layoutDirection,
|
||||
listPaddings: titlePaddings.makeEdgeInsets(context: context)
|
||||
)
|
||||
|
||||
@@ -53,7 +54,8 @@ extension DivTabs: DivBlockModeling {
|
||||
? .bySelectedPage
|
||||
: .byHighestPage,
|
||||
path: tabsContext.parentPath,
|
||||
scrollingEnabled: resolveSwitchTabsByContentSwipeEnabled(expressionResolver)
|
||||
scrollingEnabled: resolveSwitchTabsByContentSwipeEnabled(expressionResolver),
|
||||
layoutDirection: context.layoutDirection
|
||||
)
|
||||
|
||||
return try TabsBlock(
|
||||
|
||||
@@ -88,6 +88,11 @@ internal class TabContentsView: BlockView {
|
||||
self.observer = observer
|
||||
self.overscrollDelegate = overscrollDelegate
|
||||
|
||||
if oldModel?.layoutDirection != model.layoutDirection {
|
||||
collectionView.semanticContentAttribute = model
|
||||
.layoutDirection == .rightToLeft ? .forceRightToLeft : .forceLeftToRight
|
||||
}
|
||||
|
||||
if oldModel == nil || oldModel.pages !== model.pages || oldObserver !== observer {
|
||||
dataSource.models = [model.pages.map { $0.block as! CollectionCellModel }]
|
||||
|
||||
|
||||
+1
@@ -46,6 +46,7 @@ final class TabListSelectionDataSourceImpl: TabListSelectionDataSource {
|
||||
|
||||
return TabTitlesViewModel(
|
||||
items: items,
|
||||
layoutDirection: listModel.layoutDirection,
|
||||
listPaddings: listModel.listPaddings,
|
||||
titlePaddings: listModel.titleStyle.paddings,
|
||||
selectedBackgroundColor: listModel.titleStyle.activeBackgroundColor,
|
||||
|
||||
@@ -5,7 +5,7 @@ import CommonCorePublic
|
||||
final class TabListView: UIView {
|
||||
private let collectionView: UICollectionView
|
||||
private let delegate: TabListViewDelegate
|
||||
private let collectionViewLayout = UICollectionViewFlowLayout.make()
|
||||
private let collectionViewLayout = GenericCollectionViewFlowLayout.make()
|
||||
|
||||
private var selectedItemBackground: UIView!
|
||||
var isMovingToSelectedItem = false
|
||||
@@ -23,6 +23,11 @@ final class TabListView: UIView {
|
||||
dataSource = TabListViewDataSource(tabs: model.items)
|
||||
delegate.tabs = model.items
|
||||
}
|
||||
if oldValue?.layoutDirection != model.layoutDirection {
|
||||
collectionView.semanticContentAttribute = model
|
||||
.layoutDirection == .rightToLeft ? .forceRightToLeft : .forceLeftToRight
|
||||
delegate.layoutDirection = model.layoutDirection
|
||||
}
|
||||
collectionViewLayout.sectionInset = model.listPaddings
|
||||
collectionViewLayout.minimumLineSpacing = model.itemSpacing ?? 0
|
||||
selectedItemBackground.backgroundColor = model.selectedBackgroundColor.systemColor
|
||||
@@ -205,14 +210,18 @@ private struct AnimationInfo {
|
||||
}
|
||||
}
|
||||
|
||||
extension UICollectionViewFlowLayout {
|
||||
fileprivate static func make() -> UICollectionViewFlowLayout {
|
||||
let flowLayout = UICollectionViewFlowLayout()
|
||||
final class GenericCollectionViewFlowLayout: UICollectionViewFlowLayout {
|
||||
fileprivate static func make() -> GenericCollectionViewFlowLayout {
|
||||
let flowLayout = GenericCollectionViewFlowLayout()
|
||||
flowLayout.scrollDirection = .horizontal
|
||||
flowLayout.minimumLineSpacing = 0
|
||||
flowLayout.minimumInteritemSpacing = 0
|
||||
return flowLayout
|
||||
}
|
||||
|
||||
override var flipsHorizontallyInOppositeLayoutDirection: Bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private func makeCollectionView(layout: UICollectionViewLayout) -> UICollectionView {
|
||||
|
||||
@@ -5,6 +5,7 @@ import LayoutKitInterface
|
||||
|
||||
final class TabListViewDelegate: NSObject, UICollectionViewDelegateFlowLayout {
|
||||
private let collectionView: UICollectionView
|
||||
public var layoutDirection: UserInterfaceLayoutDirection = .leftToRight
|
||||
|
||||
private var itemSizes: [CGSize] = [] {
|
||||
didSet {
|
||||
@@ -66,7 +67,7 @@ final class TabListViewDelegate: NSObject, UICollectionViewDelegateFlowLayout {
|
||||
let nextItemVisibilityFraction = itemSelection - CGFloat(baseItemIndex)
|
||||
|
||||
let contentOffsetX: CGFloat
|
||||
let pillOriginX: CGFloat
|
||||
var pillOriginX: CGFloat
|
||||
|
||||
let bouncingLeft = itemSelection <= 0
|
||||
let bouncingRight = itemSelection >= CGFloat(tabs.count - 1)
|
||||
@@ -94,6 +95,11 @@ final class TabListViewDelegate: NSObject, UICollectionViewDelegateFlowLayout {
|
||||
pillOriginX = originX.interpolated(to: nextOriginX, progress: nextItemVisibilityFraction)
|
||||
}
|
||||
|
||||
if layoutDirection == .rightToLeft {
|
||||
let pillSizeWidth = itemSizes.map { $0.width }.interim(at: itemSelection)
|
||||
pillOriginX = size.width - pillSizeWidth - pillOriginX
|
||||
}
|
||||
|
||||
if let offset = offset {
|
||||
return Layout(
|
||||
contentOffset: CGPoint(x: offset, y: 0),
|
||||
|
||||
@@ -4,6 +4,7 @@ import CommonCorePublic
|
||||
|
||||
struct TabTitlesViewModel {
|
||||
let items: [TabTitleViewModel]
|
||||
let layoutDirection: UserInterfaceLayoutDirection
|
||||
let listPaddings: EdgeInsets
|
||||
let titlePaddings: EdgeInsets
|
||||
let selectedBackgroundColor: Color
|
||||
|
||||
@@ -11,6 +11,7 @@ public struct TabContentsViewModel: Equatable {
|
||||
public let footer: Block?
|
||||
public let scrollingEnabled: Bool
|
||||
public let contentInsets: EdgeInsets
|
||||
public let layoutDirection: UserInterfaceLayoutDirection
|
||||
|
||||
public init(
|
||||
pages: [TabPageViewModel],
|
||||
@@ -19,7 +20,8 @@ public struct TabContentsViewModel: Equatable {
|
||||
path: UIElementPath? = nil,
|
||||
background: Background? = nil,
|
||||
footer: Block? = nil,
|
||||
scrollingEnabled: Bool = true
|
||||
scrollingEnabled: Bool = true,
|
||||
layoutDirection: UserInterfaceLayoutDirection = .leftToRight
|
||||
) throws {
|
||||
self.path = path
|
||||
self.pages = pages
|
||||
@@ -28,6 +30,7 @@ public struct TabContentsViewModel: Equatable {
|
||||
self.background = background
|
||||
self.footer = footer
|
||||
self.scrollingEnabled = scrollingEnabled
|
||||
self.layoutDirection = layoutDirection
|
||||
|
||||
try checkConstraints()
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ public final class TabListViewModel: Equatable {
|
||||
|
||||
public let tabTitles: [UILink]
|
||||
public let titleStyle: TabTitleStyle
|
||||
public let layoutDirection: UserInterfaceLayoutDirection
|
||||
public let listPaddings: EdgeInsets
|
||||
|
||||
lazy var tabs: [TabTitleViewModel] = tabTitles.map { item in
|
||||
@@ -27,10 +28,12 @@ public final class TabListViewModel: Equatable {
|
||||
public init(
|
||||
tabTitles: [UILink],
|
||||
titleStyle: TabTitleStyle = TabTitleStyle(),
|
||||
layoutDirection: UserInterfaceLayoutDirection = .leftToRight,
|
||||
listPaddings: EdgeInsets = defaultListPaddings
|
||||
) {
|
||||
self.tabTitles = tabTitles
|
||||
self.titleStyle = titleStyle
|
||||
self.layoutDirection = layoutDirection
|
||||
self.listPaddings = listPaddings
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ extension TabContentsViewModel {
|
||||
path: path,
|
||||
background: background,
|
||||
footer: footer,
|
||||
scrollingEnabled: scrollingEnabled
|
||||
scrollingEnabled: scrollingEnabled,
|
||||
layoutDirection: layoutDirection
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user