Improve smaller text rendering

This commit is contained in:
Ilya Laktyushin
2023-07-23 04:36:11 +02:00
parent a196a1684b
commit 8eaee14c41
10 changed files with 171 additions and 339 deletions

View File

@@ -19,7 +19,7 @@ import MessageInputPanelComponent
import TextFieldComponent
import EntityKeyboard
import TooltipUI
import BlurredBackgroundComponent
import PlainButtonComponent
import AvatarNode
import ShareWithPeersScreen
import PresentationDataUtils
@@ -38,7 +38,6 @@ enum DrawingScreenType {
case sticker
}
private let privacyButtonTag = GenericComponentViewTag()
private let muteButtonTag = GenericComponentViewTag()
private let saveButtonTag = GenericComponentViewTag()
@@ -237,11 +236,9 @@ final class MediaEditorScreenComponent: Component {
private let scrubber = ComponentView<Empty>()
private let privacyButton = ComponentView<Empty>()
private let flipStickerButton = ComponentView<Empty>()
private let muteButton = ComponentView<Empty>()
private let saveButton = ComponentView<Empty>()
private let settingsButton = ComponentView<Empty>()
private let textCancelButton = ComponentView<Empty>()
private let textDoneButton = ComponentView<Empty>()
@@ -469,16 +466,6 @@ final class MediaEditorScreenComponent: Component {
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
}
if let view = self.settingsButton.view {
view.layer.animateAlpha(from: 0.0, to: view.alpha, duration: 0.2)
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
}
if let view = self.privacyButton.view {
view.layer.animateAlpha(from: 0.0, to: view.alpha, duration: 0.2)
view.layer.animateScale(from: 0.1, to: 1.0, duration: 0.2)
}
if let view = self.inputPanel.view {
view.layer.animatePosition(from: CGPoint(x: 0.0, y: 44.0), to: .zero, duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, additive: true)
view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
@@ -546,16 +533,6 @@ final class MediaEditorScreenComponent: Component {
transition.setScale(view: view, scale: 0.1)
}
if let view = self.settingsButton.view {
transition.setAlpha(view: view, alpha: 0.0)
transition.setScale(view: view, scale: 0.1)
}
if let view = self.privacyButton.view {
transition.setAlpha(view: view, alpha: 0.0)
transition.setScale(view: view, scale: 0.1)
}
if let view = self.scrubber.view {
view.layer.animatePosition(from: .zero, to: CGPoint(x: 0.0, y: 44.0), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true)
view.layer.animateAlpha(from: view.alpha, to: 0.0, duration: 0.2, removeOnCompletion: false)
@@ -673,12 +650,7 @@ final class MediaEditorScreenComponent: Component {
self.setupIfNeeded()
let isTablet: Bool
if case .regular = environment.metrics.widthClass {
isTablet = true
} else {
isTablet = false
}
let isTablet = environment.metrics.isTablet
let openDrawing = component.openDrawing
let openTools = component.openTools
@@ -745,11 +717,12 @@ final class MediaEditorScreenComponent: Component {
let doneButtonSize = self.doneButton.update(
transition: transition,
component: AnyComponent(Button(
content: AnyComponent(DoneButtonComponent(
component: AnyComponent(PlainButtonComponent(
content: AnyComponent(DoneButtonContentComponent(
backgroundColor: UIColor(rgb: 0x007aff),
icon: UIImage(bundleImageName: "Media Editor/Next")!,
title: doneButtonTitle.uppercased())),
effectAlignment: .center,
action: {
guard let controller = environment.controller() as? MediaEditorScreen else {
return
@@ -1282,70 +1255,9 @@ final class MediaEditorScreenComponent: Component {
transition.setAlpha(view: inputPanelView, alpha: isEditingTextEntity || component.isDisplayingTool || component.isDismissing || component.isInteractingWithEntities ? 0.0 : 1.0)
}
let additionalPeersCount = component.privacy.privacy.additionallyIncludePeers.count
var privacyText: String
switch component.privacy.privacy.base {
case .everyone:
privacyText = environment.strings.Story_ContextPrivacy_LabelEveryone
case .closeFriends:
privacyText = environment.strings.Story_ContextPrivacy_LabelCloseFriends
case .contacts:
if additionalPeersCount > 0 {
privacyText = environment.strings.Story_ContextPrivacy_LabelContactsExcept("\(additionalPeersCount)").string
} else {
privacyText = environment.strings.Story_ContextPrivacy_LabelContacts
}
case .nobody:
if additionalPeersCount > 0 {
privacyText = environment.strings.Story_ContextPrivacy_LabelOnlySelected(Int32(additionalPeersCount))
} else {
privacyText = environment.strings.Story_ContextPrivacy_LabelOnlyMe
}
}
let displayTopButtons = !(self.inputPanelExternalState.isEditing || isEditingTextEntity || component.isDisplayingTool)
let privacyButtonSize = self.privacyButton.update(
transition: transition,
component: AnyComponent(Button(
content: AnyComponent(
PrivacyButtonComponent(
backgroundColor: isTablet ? UIColor(rgb: 0x303030, alpha: 0.5) : UIColor(white: 0.0, alpha: 0.5),
icon: UIImage(bundleImageName: "Media Editor/Recipient")!,
text: privacyText
)
),
action: {
if let controller = environment.controller() as? MediaEditorScreen {
controller.openPrivacySettings()
}
}
).tagged(privacyButtonTag)),
environment: {},
containerSize: CGSize(width: 44.0, height: 44.0)
)
let privacyButtonFrame: CGRect
if isTablet {
privacyButtonFrame = CGRect(
origin: CGPoint(x: availableSize.width - buttonSideInset - doneButtonSize.width - privacyButtonSize.width - 24.0, y: availableSize.height - environment.safeInsets.bottom + buttonBottomInset + 1.0),
size: privacyButtonSize
)
} else {
privacyButtonFrame = CGRect(
origin: CGPoint(x: 16.0, y: environment.safeInsets.top + 20.0),
size: privacyButtonSize
)
}
if let privacyButtonView = self.privacyButton.view {
if privacyButtonView.superview == nil {
//self.addSubview(privacyButtonView)
}
transition.setPosition(view: privacyButtonView, position: privacyButtonFrame.center)
transition.setBounds(view: privacyButtonView, bounds: CGRect(origin: .zero, size: privacyButtonFrame.size))
transition.setScale(view: privacyButtonView, scale: displayTopButtons ? 1.0 : 0.01)
transition.setAlpha(view: privacyButtonView, alpha: displayTopButtons && !component.isDismissing && !component.isInteractingWithEntities ? 1.0 : 0.0)
}
let saveContentComponent: AnyComponentWithIdentity<Empty>
if component.hasAppeared {
saveContentComponent = AnyComponentWithIdentity(
@@ -2747,10 +2659,8 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
if let context = context {
let path = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius)
context.addPath(path.cgPath)
context.clip()
image.draw(in: rect)
}
@@ -3813,9 +3723,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
} else {
duration = durationValue
}
let _ = additionalPath
firstFrame = Signal<(UIImage?, UIImage?), NoError> { subscriber in
let avAsset = AVURLAsset(url: URL(fileURLWithPath: path))
let avAssetGenerator = AVAssetImageGenerator(asset: avAsset)
@@ -4135,10 +4043,6 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
}
}
func requestSettings() {
}
fileprivate func cancelVideoExport() {
if let videoExport = self.videoExport {
self.previousSavedValues = nil
@@ -4213,80 +4117,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
}
}
final class PrivacyButtonComponent: CombinedComponent {
let backgroundColor: UIColor
let icon: UIImage
let text: String
init(
backgroundColor: UIColor,
icon: UIImage,
text: String
) {
self.backgroundColor = backgroundColor
self.icon = icon
self.text = text
}
static func ==(lhs: PrivacyButtonComponent, rhs: PrivacyButtonComponent) -> Bool {
if lhs.backgroundColor != rhs.backgroundColor {
return false
}
if lhs.text != rhs.text {
return false
}
return true
}
static var body: Body {
let background = Child(BlurredBackgroundComponent.self)
let icon = Child(Image.self)
let text = Child(Text.self)
return { context in
let icon = icon.update(
component: Image(image: context.component.icon, size: CGSize(width: 9.0, height: 11.0)),
availableSize: CGSize(width: 180.0, height: 100.0),
transition: .immediate
)
let text = text.update(
component: Text(
text: context.component.text,
font: Font.medium(14.0),
color: .white
),
availableSize: CGSize(width: 180.0, height: 100.0),
transition: .immediate
)
let backgroundSize = CGSize(width: text.size.width + 38.0, height: 30.0)
let background = background.update(
component: BlurredBackgroundComponent(color: context.component.backgroundColor),
availableSize: backgroundSize,
transition: .immediate
)
context.add(background
.position(CGPoint(x: backgroundSize.width / 2.0, y: backgroundSize.height / 2.0))
.cornerRadius(min(backgroundSize.width, backgroundSize.height) / 2.0)
.clipsToBounds(true)
)
context.add(icon
.position(CGPoint(x: 16.0, y: backgroundSize.height / 2.0))
)
context.add(text
.position(CGPoint(x: backgroundSize.width / 2.0 + 7.0, y: backgroundSize.height / 2.0))
)
return backgroundSize
}
}
}
final class DoneButtonComponent: CombinedComponent {
final class DoneButtonContentComponent: CombinedComponent {
let backgroundColor: UIColor
let icon: UIImage
let title: String?
@@ -4301,7 +4132,7 @@ final class DoneButtonComponent: CombinedComponent {
self.title = title
}
static func ==(lhs: DoneButtonComponent, rhs: DoneButtonComponent) -> Bool {
static func ==(lhs: DoneButtonContentComponent, rhs: DoneButtonContentComponent) -> Bool {
if lhs.backgroundColor != rhs.backgroundColor {
return false
}

View File

@@ -383,8 +383,6 @@ public final class SaveProgressScreenComponent: Component {
}
}
private let storyDimensions = CGSize(width: 1080.0, height: 1920.0)
public final class SaveProgressScreen: ViewController {
fileprivate final class Node: ViewControllerTracingNode, UIGestureRecognizerDelegate {
private weak var controller: SaveProgressScreen?