Skip to content

Commit

Permalink
Release 23.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-divkit committed Mar 27, 2023
1 parent fbc5203 commit c058068
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 38 deletions.
33 changes: 27 additions & 6 deletions DivKit/Actions/DivActionURLHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public final class DivActionURLHandler {
index: index,
numberOfPages: pagerState.numberOfPages
)
case is TabViewState:
setTabsCurrentItem(id: id, index: index)
case let tabsState as TabViewState:
setTabsCurrentItem(id: id, index: index, countOfPages: tabsState.countOfPages)
default:
return
}
Expand All @@ -172,7 +172,16 @@ public final class DivActionURLHandler {
numberOfPages: pagerState.numberOfPages
)
case let tabsState as TabViewState:
setTabsCurrentItem(id: id, index: Int(tabsState.selectedPageIndex) + 1)
let nextIndex = getNextIndex(
current: Int(tabsState.selectedPageIndex),
count: tabsState.countOfPages,
overflow: overflow
)
setTabsCurrentItem(
id: id,
index: nextIndex,
countOfPages: tabsState.countOfPages
)
default:
return
}
Expand Down Expand Up @@ -212,7 +221,16 @@ public final class DivActionURLHandler {
numberOfPages: pagerState.numberOfPages
)
case let tabsState as TabViewState:
setTabsCurrentItem(id: id, index: Int(tabsState.selectedPageIndex) - 1)
let prevIndex = getPreviousIndex(
current: Int(tabsState.selectedPageIndex),
count: tabsState.countOfPages,
overflow: overflow
)
setTabsCurrentItem(
id: id,
index: prevIndex,
countOfPages: tabsState.countOfPages
)
default:
return
}
Expand Down Expand Up @@ -253,10 +271,13 @@ public final class DivActionURLHandler {
)
}

private func setTabsCurrentItem(id: String, index: Int) {
private func setTabsCurrentItem(id: String, index: Int, countOfPages: Int) {
blockStateStorage.setState(
id: id,
state: TabViewState(selectedPageIndex: CGFloat(max(0, index)))
state: TabViewState(
selectedPageIndex: CGFloat(max(0, index)),
countOfPages: countOfPages
)
)
}
}
2 changes: 1 addition & 1 deletion DivKit/DivKitInfo.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
public enum DivKitInfo {
public static let version = "23.6.0"
public static let version = "23.7.0"
}
3 changes: 1 addition & 2 deletions DivKit/Extensions/DelayExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import LayoutKit

extension Delay {
init?(milliseconds: Int) {
guard milliseconds >= 0 else { return nil }
init(milliseconds: Int) {
self.init(Double(milliseconds) / 1000)
}
}
8 changes: 2 additions & 6 deletions DivKit/Extensions/DivAnimationExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ extension DivAnimation {
kind: kind,
start: startValue ?? kind.defaultStartValue(for: type),
end: endValue ?? kind.defaultEndValue(for: type),
duration: Duration(milliseconds: resolveDuration(expressionResolver)) ?? .default,
delay: Delay(milliseconds: resolveStartDelay(expressionResolver)) ?? 0,
duration: Duration(milliseconds: resolveDuration(expressionResolver)),
delay: Delay(milliseconds: resolveStartDelay(expressionResolver)),
timingFunction: resolveInterpolator(expressionResolver).asTimingFunction()
)

Expand Down Expand Up @@ -106,7 +106,3 @@ extension TimeOrientation {
}
}
}

extension Duration {
fileprivate static let `default` = Duration(milliseconds: 100)!
}
8 changes: 3 additions & 5 deletions DivKit/Extensions/DivAppearanceTransitionExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ extension DivAppearanceTransition {
kind: kind,
start: type == .appearing ? value1 : value2,
end: type == .appearing ? value2 : value1,
duration: Duration(milliseconds: transition.resolveDuration(expressionResolver))
?? 0.3,
delay: Delay(milliseconds: transition.resolveStartDelay(expressionResolver)) ?? 0,
timingFunction: transition.resolveInterpolator(expressionResolver)
.asTimingFunction()
duration: Duration(milliseconds: transition.resolveDuration(expressionResolver)),
delay: Delay(milliseconds: transition.resolveStartDelay(expressionResolver)),
timingFunction: transition.resolveInterpolator(expressionResolver).asTimingFunction()
)

return [animation]
Expand Down
2 changes: 1 addition & 1 deletion DivKit/Extensions/DivBase/DivBaseExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ extension DivTooltip {
return BlockTooltip(
id: id,
block: block,
duration: Duration(milliseconds: resolveDuration(expressionResolver)) ?? 0,
duration: Duration(milliseconds: resolveDuration(expressionResolver)),
offset: offset?.cast(with: expressionResolver) ?? .zero,
position: position
)
Expand Down
6 changes: 2 additions & 4 deletions DivKit/Extensions/DivChangeTransitionExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ extension DivChangeTransition {
switch self {
case let .divChangeBoundsTransition(transition):
return ChangeBoundsTransition(
duration: Duration(
milliseconds: transition.resolveDuration(expressionResolver)
) ?? 0.3,
delay: Delay(milliseconds: transition.resolveStartDelay(expressionResolver)) ?? 0,
duration: Duration(milliseconds: transition.resolveDuration(expressionResolver)),
delay: Delay(milliseconds: transition.resolveStartDelay(expressionResolver)),
timingFunction: transition.resolveInterpolator(expressionResolver)
.asTimingFunction()
)
Expand Down
4 changes: 2 additions & 2 deletions DivKit/Extensions/DivFadeTransitionExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ extension DivFadeTransition {
kind: .fade,
start: resolveAlpha(expressionResolver),
end: 1,
duration: Duration(milliseconds: resolveDuration(expressionResolver)) ?? 0.3,
delay: Delay(milliseconds: resolveStartDelay(expressionResolver)) ?? 0,
duration: Duration(milliseconds: resolveDuration(expressionResolver)),
delay: Delay(milliseconds: resolveStartDelay(expressionResolver)),
timingFunction: resolveInterpolator(expressionResolver).asTimingFunction()
)
}
Expand Down
4 changes: 2 additions & 2 deletions DivKit/Extensions/DivStateExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ extension DivAnimation {
kind: kind,
start: resolveStartValue(expressionResolver) ?? kind.defaultStartValue(for: type),
end: resolveEndValue(expressionResolver) ?? kind.defaultEndValue(for: type),
duration: Duration(milliseconds: resolveDuration(expressionResolver)) ?? 0.3,
delay: Delay(milliseconds: resolveStartDelay(expressionResolver)) ?? 0,
duration: Duration(milliseconds: resolveDuration(expressionResolver)),
delay: Delay(milliseconds: resolveStartDelay(expressionResolver)),
timingFunction: resolveInterpolator(expressionResolver).asTimingFunction()
)

Expand Down
3 changes: 2 additions & 1 deletion DivKit/Extensions/DivTabsExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ extension DivTabs: DivBlockModeling {
index = CGFloat(resolveSelectedTab(context.expressionResolver))
}
let newState = TabViewState(
selectedPageIndex: min(index, CGFloat(tabs.count) - 1)
selectedPageIndex: min(index, CGFloat(tabs.count) - 1),
countOfPages: tabs.count
)
stateStorage.setState(path: path, state: newState)
return newState
Expand Down
3 changes: 1 addition & 2 deletions DivKit/Extensions/DurationExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import LayoutKit

extension Duration {
init?(milliseconds: Int) {
guard milliseconds > 0 else { return nil }
init(milliseconds: Int) {
self.init(Double(milliseconds) / 1000)
}
}
2 changes: 1 addition & 1 deletion LayoutKit/LayoutKit/Blocks/Duration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public struct Duration: ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral,
public let value: Double

public init(_ value: Double) {
precondition(value > 0, "Duration must be positive number")
precondition(value >= 0, "Duration must be non-negative number")
self.value = value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ internal class TabContentsView: BlockView {

private func updateSelectedPageIndexFromRelativeContentOffset(isIntermediate: Bool) {
notifyDelegateAboutSelectedPageIndexChange(
relativeContentOffset,
selectedPageIndex: relativeContentOffset,
countOfPages: model.pages.count,
isIntermediate: isIntermediate
)
}

private func notifyDelegateAboutSelectedPageIndexChange(
_ selectedPageIndex: CGFloat,
selectedPageIndex: CGFloat,
countOfPages: Int,
isIntermediate: Bool
) {
let roundedIndex = selectedPageIndex.rounded(.toNearestOrAwayFromZero)
Expand All @@ -224,7 +226,7 @@ internal class TabContentsView: BlockView {
let index = isIntermediate ? selectedPageIndex : roundedIndex
self.selectedPageIndex = index
updatesDelegate?.onSelectedPageIndexChanged(index, inModel: model)
let state = TabViewState(selectedPageIndex: index)
let state = TabViewState(selectedPageIndex: index, countOfPages: countOfPages)
observer?.elementStateChanged(state, forPath: model.path)
}
}
Expand Down
6 changes: 4 additions & 2 deletions LayoutKit/LayoutKit/ViewModels/TabbedPages/TabViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import CommonCore

public struct TabViewState: ElementState, Equatable {
public let selectedPageIndex: CGFloat
public let countOfPages: Int

public static let `default` = TabViewState(selectedPageIndex: 0)
public static let `default` = TabViewState(selectedPageIndex: 0, countOfPages: 0)

public init(selectedPageIndex: CGFloat) {
public init(selectedPageIndex: CGFloat, countOfPages: Int) {
self.selectedPageIndex = selectedPageIndex
self.countOfPages = countOfPages
}
}

0 comments on commit c058068

Please sign in to comment.