Skip to content

Commit

Permalink
ton support
Browse files Browse the repository at this point in the history
  • Loading branch information
overtake committed Oct 4, 2019
1 parent 45ee451 commit 35421a7
Show file tree
Hide file tree
Showing 150 changed files with 9,568 additions and 524 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ url=https://github.com/overtake/Sparkle
url=git@github.com:overtake/lottie-ios.git
[submodule "submodules/telegram-ios"]
path = submodules/telegram-ios
url=git@github.com:TelegramMessenger/Telegram-iOS.git
url=git@gitlab.com:peter-iakovlev/telegram-ios.git
[submodule "submodules/rlottie"]
path = submodules/rlottie
url=git@github.com:overtake/rlottie.git
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>RLottieMac.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>61</integer>
<integer>60</integer>
</dict>
</dict>
</dict>
Expand Down
4 changes: 4 additions & 0 deletions TGUIKit/TGUIKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
C2FD33E71E6952A8008D13D4 /* RadialProgressContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2FD33E61E6952A8008D13D4 /* RadialProgressContainerView.swift */; };
D04D214C230ED78300609388 /* SPopoverRowItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04D214A230ED78300609388 /* SPopoverRowItem.swift */; };
D04D214D230ED78300609388 /* SPopoverViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D04D214B230ED78300609388 /* SPopoverViewController.swift */; };
D050518E2342A75D00D93176 /* DisplayLinkAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D050518D2342A75D00D93176 /* DisplayLinkAnimator.swift */; };
D0558D8221528DF5006B403D /* ModalTouchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0558D8121528DF5006B403D /* ModalTouchBar.swift */; };
D05F392022FB37920040F341 /* DatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05F391F22FB37920040F341 /* DatePicker.swift */; };
D0BEB9922163C1F00055B718 /* SelectionRectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0BEB9912163C1F00055B718 /* SelectionRectView.swift */; };
Expand Down Expand Up @@ -215,6 +216,7 @@
C2FD33E61E6952A8008D13D4 /* RadialProgressContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadialProgressContainerView.swift; sourceTree = "<group>"; };
D04D214A230ED78300609388 /* SPopoverRowItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SPopoverRowItem.swift; sourceTree = "<group>"; };
D04D214B230ED78300609388 /* SPopoverViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SPopoverViewController.swift; sourceTree = "<group>"; };
D050518D2342A75D00D93176 /* DisplayLinkAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayLinkAnimator.swift; sourceTree = "<group>"; };
D0558D8121528DF5006B403D /* ModalTouchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalTouchBar.swift; sourceTree = "<group>"; };
D05F391F22FB37920040F341 /* DatePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePicker.swift; sourceTree = "<group>"; };
D0BEB9912163C1F00055B718 /* SelectionRectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectionRectView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -338,6 +340,7 @@
C291ED9A1DB361ED008C6B2A /* KeyboardUtils.swift */,
C226741C1DBCDBA8000BA9ED /* ContainableController.swift */,
C28BAB0C1DF8550E0027CE3A /* WindowSaver.swift */,
D050518D2342A75D00D93176 /* DisplayLinkAnimator.swift */,
);
name = utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -666,6 +669,7 @@
9F6281292037389200B2D3C9 /* CheckBox.swift in Sources */,
C226741D1DBCDBA8000BA9ED /* ContainableController.swift in Sources */,
C253A9651D91B24100CDC850 /* TextViewLabel.swift in Sources */,
D050518E2342A75D00D93176 /* DisplayLinkAnimator.swift in Sources */,
C219E1FA1D8C316C0042F0C8 /* TitledBarView.swift in Sources */,
C28BAB0D1DF8550E0027CE3A /* WindowSaver.swift in Sources */,
C2303E7C1D99880B00098E12 /* Modal.swift in Sources */,
Expand Down
66 changes: 66 additions & 0 deletions TGUIKit/TGUIKit/CAAnimationUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,69 @@ public extension CALayer {
}
*/
}


struct ViewportItemSpring {
let stiffness: CGFloat
let damping: CGFloat
let mass: CGFloat
var velocity: CGFloat = 0.0

init(stiffness: CGFloat, damping: CGFloat, mass: CGFloat) {
self.stiffness = stiffness
self.damping = damping
self.mass = mass
}
}

private func a(_ a1: CGFloat, _ a2: CGFloat) -> CGFloat
{
return 1.0 - 3.0 * a2 + 3.0 * a1
}

private func b(_ a1: CGFloat, _ a2: CGFloat) -> CGFloat
{
return 3.0 * a2 - 6.0 * a1
}

private func c(_ a1: CGFloat) -> CGFloat
{
return 3.0 * a1
}

private func calcBezier(_ t: CGFloat, _ a1: CGFloat, _ a2: CGFloat) -> CGFloat
{
return ((a(a1, a2)*t + b(a1, a2))*t + c(a1)) * t
}

private func calcSlope(_ t: CGFloat, _ a1: CGFloat, _ a2: CGFloat) -> CGFloat
{
return 3.0 * a(a1, a2) * t * t + 2.0 * b(a1, a2) * t + c(a1)
}

private func getTForX(_ x: CGFloat, _ x1: CGFloat, _ x2: CGFloat) -> CGFloat {
var t = x
var i = 0
while i < 4 {
let currentSlope = calcSlope(t, x1, x2)
if currentSlope == 0.0 {
return t
} else {
let currentX = calcBezier(t, x1, x2) - x
t -= currentX / currentSlope
}

i += 1
}

return t
}

public func bezierPoint(_ x1: CGFloat, _ y1: CGFloat, _ x2: CGFloat, _ y2: CGFloat, _ x: CGFloat) -> CGFloat
{
var value = calcBezier(getTForX(x, x1, x2), y1, y2)
if value >= 0.997 {
value = 1.0
}
return value
}
11 changes: 8 additions & 3 deletions TGUIKit/TGUIKit/Control.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ open class Control: View {
private var handlers:[(ControlEvent,(Control) -> Void)] = []
private var stateHandlers:[(ControlState,(Control) -> Void)] = []

private var backgroundState:[ControlState:NSColor] = [:]
private(set) internal var backgroundState:[ControlState:NSColor] = [:]
private var mouseMovedInside: Bool = true
private var longInvoked: Bool = false
open override var backgroundColor: NSColor {
Expand Down Expand Up @@ -113,11 +113,16 @@ open class Control: View {

public func apply(state:ControlState) -> Void {
let state:ControlState = self.isSelected ? .Highlight : state
if let color = backgroundState[state] {
self.layer?.backgroundColor = color.cgColor
if isEnabled {
if let color = backgroundState[state] {
self.layer?.backgroundColor = color.cgColor
} else {
self.layer?.backgroundColor = backgroundState[.Normal]?.cgColor ?? self.backgroundColor.cgColor
}
} else {
self.layer?.backgroundColor = backgroundState[.Normal]?.cgColor ?? self.backgroundColor.cgColor
}

if animates {
self.layer?.animateBackground()
}
Expand Down
115 changes: 115 additions & 0 deletions TGUIKit/TGUIKit/DisplayLinkAnimator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//
// DisplayLinkAnimator.swift
// TGUIKit
//
// Created by Mikhail Filimonov on 30/09/2019.
// Copyright © 2019 Telegram. All rights reserved.
//

import Cocoa
import SwiftSignalKitMac

private final class DisplayLinkTarget: NSObject {
private let f: () -> Void

init(_ f: @escaping () -> Void) {
self.f = f
}

@objc func event() {
self.f()
}
}

public final class DisplayLinkAnimator {
private var displayLink: SwiftSignalKitMac.Timer!
private let duration: Double
private let fromValue: CGFloat
private let toValue: CGFloat
private let startTime: Double
private let update: (CGFloat) -> Void
private let completion: () -> Void
private var completed = false

public init(duration: Double, from fromValue: CGFloat, to toValue: CGFloat, update: @escaping (CGFloat) -> Void, completion: @escaping () -> Void) {
self.duration = duration
self.fromValue = fromValue
self.toValue = toValue
self.update = update
self.completion = completion

self.startTime = CACurrentMediaTime()

self.displayLink = SwiftSignalKitMac.Timer.init(timeout: 0.016, repeat: true, completion: { [weak self] in
self?.tick()
}, queue: .mainQueue())

self.displayLink.start()
}

deinit {
self.displayLink.invalidate()
}

public func invalidate() {
self.displayLink.invalidate()
}

@objc private func tick() {
if self.completed {
return
}
let timestamp = CACurrentMediaTime()
var t = (timestamp - self.startTime) / self.duration
t = max(0.0, t)
t = min(1.0, t)
self.update(self.fromValue * CGFloat(1 - t) + self.toValue * CGFloat(t))
if abs(t - 1.0) < Double.ulpOfOne {
self.completed = true
self.displayLink.invalidate()
self.completion()
}
}
}

public final class ConstantDisplayLinkAnimator {
private var displayLink: SwiftSignalKitMac.Timer?
private let update: () -> Void
private var completed = false

public var isPaused: Bool = true {
didSet {
if self.isPaused != oldValue {
if self.isPaused {
self.displayLink?.invalidate()
} else {
self.displayLink = SwiftSignalKitMac.Timer(timeout: 0.016, repeat: true, completion: { [weak self] in
self?.tick()
}, queue: .mainQueue())

self.displayLink?.start()
}
}
}
}

public init(update: @escaping () -> Void) {
self.update = update
}

deinit {
self.displayLink?.invalidate()
}

public func invalidate() {
self.displayLink?.invalidate()
}

@objc private func tick() {
if self.completed {
return
}
self.update()
}
}

1 change: 1 addition & 0 deletions TGUIKit/TGUIKit/ImageButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ open class ImageButton: Button {
override func prepare() {
super.prepare()
imageView.animates = true
imageView.isEventLess = true
self.addSubview(imageView)
}

Expand Down
77 changes: 38 additions & 39 deletions TGUIKit/TGUIKit/MajorNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ open class MajorNavigationController: NavigationViewController, SplitViewDelegat
controller.navigationController = self




if genericView.state == .dual {
controller.loadViewIfNeeded(NSMakeRect(0, 0, genericView.frame.width - 350, genericView.frame.height))
} else {
Expand All @@ -153,45 +151,46 @@ open class MajorNavigationController: NavigationViewController, SplitViewDelegat

genericView.update()


pushDisposable.set((controller.ready.get() |> deliverOnMainQueue |> take(1)).start(next: {[weak self] _ in
if let strongSelf = self {
let isMajorController = controller.className == NSStringFromClass(strongSelf.majorClass)
let removeAnimateFlag = strongSelf.stackCount == 2 && isMajorController && !strongSelf.alwaysAnimate

if isMajorController {
for controller in strongSelf.stack {
controller.didRemovedFromStack()
self.controller.ableToNextController(controller, { [weak self] controller, result in
if result {
self?.pushDisposable.set((controller.ready.get() |> deliverOnMainQueue |> take(1)).start(next: {[weak self] _ in
if let strongSelf = self {
let isMajorController = controller.className == NSStringFromClass(strongSelf.majorClass)
let removeAnimateFlag = strongSelf.stackCount == 2 && isMajorController && !strongSelf.alwaysAnimate

if isMajorController {
for controller in strongSelf.stack {
controller.didRemovedFromStack()
}
strongSelf.stack.removeAll()

strongSelf.stack.append(strongSelf.empty)
}

if let index = strongSelf.stack.firstIndex(of: controller) {
strongSelf.stack.remove(at: index)
}

strongSelf.stack.append(controller)

let anim = animated && (!isMajorController || strongSelf.controller != strongSelf.defaultEmpty) && !removeAnimateFlag

let newStyle:ViewControllerStyle
if let style = style {
newStyle = style
} else {
newStyle = anim ? .push : .none
}

CATransaction.begin()
strongSelf.show(controller, newStyle)
CATransaction.commit()
}
strongSelf.stack.removeAll()

strongSelf.stack.append(strongSelf.empty)
}

if let index = strongSelf.stack.firstIndex(of: controller) {
strongSelf.stack.remove(at: index)
}

strongSelf.stack.append(controller)

let anim = animated && (!isMajorController || strongSelf.controller != strongSelf.defaultEmpty) && !removeAnimateFlag

let newStyle:ViewControllerStyle
if let style = style {
newStyle = style
} else {
newStyle = anim ? .push : .none
}

CATransaction.begin()
strongSelf.show(controller, newStyle)
CATransaction.commit()




}))
}
}))
})


}


Expand Down
Loading

0 comments on commit 35421a7

Please sign in to comment.