mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Various fixes
This commit is contained in:
parent
8d87d569a7
commit
29f7c8c9f0
@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
private func findTaggedViewImpl(view: UIView, tag: Any) -> UIView? {
|
||||
public func findTaggedComponentViewImpl(view: UIView, tag: Any) -> UIView? {
|
||||
if let view = view as? ComponentTaggedView {
|
||||
if view.matches(tag: tag) {
|
||||
return view
|
||||
@ -9,7 +9,7 @@ private func findTaggedViewImpl(view: UIView, tag: Any) -> UIView? {
|
||||
}
|
||||
|
||||
for subview in view.subviews {
|
||||
if let result = findTaggedViewImpl(view: subview, tag: tag) {
|
||||
if let result = findTaggedComponentViewImpl(view: subview, tag: tag) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
@ -131,7 +131,7 @@ public final class ComponentHostView<EnvironmentType>: UIView {
|
||||
return nil
|
||||
}
|
||||
|
||||
return findTaggedViewImpl(view: componentView, tag: tag)
|
||||
return findTaggedComponentViewImpl(view: componentView, tag: tag)
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ public final class ComponentView<EnvironmentType> {
|
||||
guard let view = self.view else {
|
||||
return nil
|
||||
}
|
||||
return findTaggedViewImpl(view: view, tag: tag)
|
||||
return findTaggedComponentViewImpl(view: view, tag: tag)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,14 +292,30 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
}
|
||||
|
||||
func removeAll() {
|
||||
self.clear()
|
||||
self.clear(animated: true)
|
||||
self.selectionChanged(nil)
|
||||
self.hasSelectionChanged(false)
|
||||
}
|
||||
|
||||
private func clear() {
|
||||
for case let view as DrawingEntityView in self.subviews {
|
||||
view.removeFromSuperview()
|
||||
private func clear(animated: Bool = false) {
|
||||
if animated {
|
||||
for case let view as DrawingEntityView in self.subviews {
|
||||
if let selectionView = view.selectionView {
|
||||
selectionView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak selectionView] _ in
|
||||
selectionView?.removeFromSuperview()
|
||||
})
|
||||
}
|
||||
view.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak view] _ in
|
||||
view?.removeFromSuperview()
|
||||
})
|
||||
view.layer.animateScale(from: 0.0, to: -0.99, duration: 0.2, removeOnCompletion: false, additive: true)
|
||||
}
|
||||
|
||||
} else {
|
||||
for case let view as DrawingEntityView in self.subviews {
|
||||
view.selectionView?.removeFromSuperview()
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -750,8 +750,18 @@ private final class DrawingScreenComponent: CombinedComponent {
|
||||
)
|
||||
context.add(textSettings
|
||||
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height - environment.safeInsets.bottom - textSettings.size.height / 2.0 - 89.0))
|
||||
.appear(.default(scale: false, alpha: true))
|
||||
.disappear(.default(scale: false, alpha: true))
|
||||
.appear(Transition.Appear({ _, view, transition in
|
||||
if let view = findTaggedComponentViewImpl(view: view, tag: textSettingsTag) as? TextFontComponent.View, !transition.animation.isImmediate {
|
||||
view.animateIn()
|
||||
}
|
||||
}))
|
||||
.disappear(Transition.Disappear({ view, transition, completion in
|
||||
if let view = findTaggedComponentViewImpl(view: view, tag: textSettingsTag) as? TextFontComponent.View, !transition.animation.isImmediate {
|
||||
view.animateOut(completion: completion)
|
||||
} else {
|
||||
completion()
|
||||
}
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
@ -2000,11 +2010,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
|
||||
if let view = self.componentHost.findTaggedView(tag: sizeSliderTag) {
|
||||
view.layer.animatePosition(from: CGPoint(), to: CGPoint(x: -33.0, y: 0.0), duration: 0.3, removeOnCompletion: false, additive: true)
|
||||
}
|
||||
if let view = self.componentHost.findTaggedView(tag: textSettingsTag) {
|
||||
view.alpha = 0.0
|
||||
view.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3)
|
||||
}
|
||||
|
||||
|
||||
let colorTags = [color1Tag, color2Tag, color3Tag, color4Tag, color5Tag, color6Tag, color7Tag, color8Tag]
|
||||
for tag in colorTags {
|
||||
if let view = self.componentHost.findTaggedView(tag: tag) {
|
||||
@ -2018,7 +2024,12 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController {
|
||||
view.animateOut(completion: {
|
||||
completion()
|
||||
})
|
||||
} else if let view = self.componentHost.findTaggedView(tag: textSettingsTag) as? TextFontComponent.View {
|
||||
view.animateOut(completion: {
|
||||
completion()
|
||||
})
|
||||
}
|
||||
|
||||
if let view = self.componentHost.findTaggedView(tag: modeTag) as? ModeAndSizeComponent.View {
|
||||
view.animateOut()
|
||||
}
|
||||
|
@ -181,13 +181,15 @@ final class TextFontComponent: Component {
|
||||
|
||||
let values: [DrawingTextFont]
|
||||
let selectedValue: DrawingTextFont
|
||||
let tag: AnyObject?
|
||||
let updated: (DrawingTextFont) -> Void
|
||||
|
||||
init(styleButton: AnyComponent<Empty>, alignmentButton: AnyComponent<Empty>, values: [DrawingTextFont], selectedValue: DrawingTextFont, updated: @escaping (DrawingTextFont) -> Void) {
|
||||
init(styleButton: AnyComponent<Empty>, alignmentButton: AnyComponent<Empty>, values: [DrawingTextFont], selectedValue: DrawingTextFont, tag: AnyObject?, updated: @escaping (DrawingTextFont) -> Void) {
|
||||
self.styleButton = styleButton
|
||||
self.alignmentButton = alignmentButton
|
||||
self.values = values
|
||||
self.selectedValue = selectedValue
|
||||
self.tag = tag
|
||||
self.updated = updated
|
||||
}
|
||||
|
||||
@ -195,7 +197,7 @@ final class TextFontComponent: Component {
|
||||
return lhs.styleButton == rhs.styleButton && lhs.alignmentButton == rhs.alignmentButton && lhs.values == rhs.values && lhs.selectedValue == rhs.selectedValue
|
||||
}
|
||||
|
||||
public final class View: UIView {
|
||||
final class View: UIView, ComponentTaggedView {
|
||||
private let styleButtonHost: ComponentView<Empty>
|
||||
private let alignmentButtonHost: ComponentView<Empty>
|
||||
|
||||
@ -206,8 +208,19 @@ final class TextFontComponent: Component {
|
||||
private let maskCenter = SimpleLayer()
|
||||
private let maskRight = SimpleGradientLayer()
|
||||
|
||||
private var component: TextFontComponent?
|
||||
private var updated: (DrawingTextFont) -> Void = { _ in }
|
||||
|
||||
public func matches(tag: Any) -> Bool {
|
||||
if let component = self.component, let componentTag = component.tag {
|
||||
let tag = tag as AnyObject
|
||||
if componentTag === tag {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override init(frame: CGRect) {
|
||||
if #available(iOS 11.0, *) {
|
||||
self.scrollView.contentInsetAdjustmentBehavior = .never
|
||||
@ -257,8 +270,57 @@ final class TextFontComponent: Component {
|
||||
}
|
||||
}
|
||||
|
||||
func animateIn() {
|
||||
var delay: Double = 0.0
|
||||
|
||||
if let view = self.styleButtonHost.view {
|
||||
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
||||
view.layer.animateScale(from: 0.01, to: 1.0, duration: 0.2)
|
||||
delay += 0.02
|
||||
}
|
||||
|
||||
if let view = self.alignmentButtonHost.view {
|
||||
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, delay: delay)
|
||||
view.layer.animateScale(from: 0.01, to: 1.0, duration: 0.2, delay: delay)
|
||||
delay += 0.02
|
||||
}
|
||||
|
||||
if let component = self.component {
|
||||
for value in component.values {
|
||||
if let view = self.buttons[value] {
|
||||
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, delay: delay)
|
||||
view.layer.animateScale(from: 0.01, to: 1.0, duration: 0.2, delay: delay)
|
||||
delay += 0.02
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func animateOut(completion: @escaping () -> Void) {
|
||||
if let view = self.styleButtonHost.view {
|
||||
view.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, removeOnCompletion: false)
|
||||
}
|
||||
|
||||
if let view = self.alignmentButtonHost.view {
|
||||
view.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, removeOnCompletion: false)
|
||||
}
|
||||
|
||||
if let component = self.component {
|
||||
for value in component.values {
|
||||
if let view = self.buttons[value] {
|
||||
view.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, removeOnCompletion: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { _ in
|
||||
completion()
|
||||
})
|
||||
}
|
||||
|
||||
private var previousValue: DrawingTextFont?
|
||||
func update(component: TextFontComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
|
||||
self.component = component
|
||||
self.updated = component.updated
|
||||
|
||||
var contentWidth: CGFloat = 10.0
|
||||
@ -462,26 +524,7 @@ final class TextSettingsComponent: CombinedComponent {
|
||||
func makeState() -> State {
|
||||
State()
|
||||
}
|
||||
|
||||
final class View: UIView, ComponentTaggedView {
|
||||
var componentTag: AnyObject?
|
||||
public func matches(tag: Any) -> Bool {
|
||||
if let componentTag = self.componentTag {
|
||||
let tag = tag as AnyObject
|
||||
if componentTag === tag {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func makeView() -> View {
|
||||
let view = View()
|
||||
view.componentTag = self.tag
|
||||
return view
|
||||
}
|
||||
|
||||
|
||||
static var body: Body {
|
||||
let colorButton = Child(ColorSwatchComponent.self)
|
||||
let colorButtonTag = GenericComponentViewTag()
|
||||
@ -576,6 +619,7 @@ final class TextSettingsComponent: CombinedComponent {
|
||||
),
|
||||
values: DrawingTextFont.allCases,
|
||||
selectedValue: component.font,
|
||||
tag: component.tag,
|
||||
updated: { font in
|
||||
updateFont(font)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user