diff --git a/submodules/DrawingUI/BUILD b/submodules/DrawingUI/BUILD index 6f8d77266d..fdde9b283e 100644 --- a/submodules/DrawingUI/BUILD +++ b/submodules/DrawingUI/BUILD @@ -82,6 +82,7 @@ swift_library( "//submodules/Components/ViewControllerComponent:ViewControllerComponent", "//submodules/Components/SheetComponent:SheetComponent", "//submodules/Components/MultilineTextComponent:MultilineTextComponent", + "//submodules/Components/BlurredBackgroundComponent:BlurredBackgroundComponent", "//submodules/AnimatedStickerNode:AnimatedStickerNode", "//submodules/TelegramAnimatedStickerNode:TelegramAnimatedStickerNode", "//submodules/StickerResources:StickerResources", diff --git a/submodules/DrawingUI/Sources/ColorPickerScreen.swift b/submodules/DrawingUI/Sources/ColorPickerScreen.swift index a1f1d73de2..34b0a727ed 100644 --- a/submodules/DrawingUI/Sources/ColorPickerScreen.swift +++ b/submodules/DrawingUI/Sources/ColorPickerScreen.swift @@ -10,6 +10,7 @@ import AccountContext import TelegramPresentationData import SheetComponent import ViewControllerComponent +import BlurredBackgroundComponent import SegmentedControlNode import MultilineTextComponent import HexColor @@ -1850,59 +1851,6 @@ final class ColorSwatchComponent: Component { } } - -class BlurredRectangle: Component { - let color: UIColor - let radius: CGFloat - - init(color: UIColor, radius: CGFloat = 0.0) { - self.color = color - self.radius = radius - } - - static func ==(lhs: BlurredRectangle, rhs: BlurredRectangle) -> Bool { - if !lhs.color.isEqual(rhs.color) { - return false - } - if lhs.radius != rhs.radius { - return false - } - return true - } - - final class View: UIView { - private let background: NavigationBackgroundNode - - init() { - self.background = NavigationBackgroundNode(color: .clear) - - super.init(frame: CGRect()) - - self.addSubview(self.background.view) - } - - required init?(coder aDecoder: NSCoder) { - preconditionFailure() - } - - func update(component: BlurredRectangle, availableSize: CGSize, transition: Transition) -> CGSize { - transition.setFrame(view: self.background.view, frame: CGRect(origin: CGPoint(), size: availableSize)) - self.background.updateColor(color: component.color, transition: .immediate) - self.background.update(size: availableSize, cornerRadius: component.radius, transition: .immediate) - - return availableSize - } - } - - func makeView() -> View { - return View() - } - - func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: Transition) -> CGSize { - return view.update(component: self, availableSize: availableSize, transition: transition) - } -} - private final class ColorPickerContent: CombinedComponent { typealias EnvironmentType = ViewControllerComponentContainer.Environment @@ -2054,9 +2002,8 @@ private final class ColorPickerContent: CombinedComponent { AnyComponentWithIdentity( id: "background", component: AnyComponent( - BlurredRectangle( - color: UIColor(rgb: 0x888888, alpha: 0.1), - radius: 15.0 + BlurredBackgroundComponent( + color: UIColor(rgb: 0x888888, alpha: 0.1) ) ) ), @@ -2076,6 +2023,8 @@ private final class ColorPickerContent: CombinedComponent { ) context.add(closeButton .position(CGPoint(x: context.availableSize.width - environment.safeInsets.right - closeButton.size.width - 1.0, y: 29.0)) + .clipsToBounds(true) + .cornerRadius(15.0) ) let title = title.update( diff --git a/submodules/DrawingUI/Sources/DrawingScreen.swift b/submodules/DrawingUI/Sources/DrawingScreen.swift index fe74b08ada..4351914e76 100644 --- a/submodules/DrawingUI/Sources/DrawingScreen.swift +++ b/submodules/DrawingUI/Sources/DrawingScreen.swift @@ -15,6 +15,7 @@ import LegacyComponents import ComponentDisplayAdapters import LottieAnimationComponent import ViewControllerComponent +import BlurredBackgroundComponent import ContextUI import ChatEntityKeyboardInputNode import EntityKeyboard @@ -1787,9 +1788,8 @@ private final class DrawingScreenComponent: CombinedComponent { AnyComponentWithIdentity( id: "background", component: AnyComponent( - BlurredRectangle( - color: UIColor(rgb: 0x888888, alpha: 0.3), - radius: 12.0 + BlurredBackgroundComponent( + color: UIColor(rgb: 0x888888, alpha: 0.3) ) ) ), @@ -1826,6 +1826,7 @@ private final class DrawingScreenComponent: CombinedComponent { .position(CGPoint(x: rightEdge - addButton.size.width / 2.0 - 2.0, y: context.availableSize.height - environment.safeInsets.bottom - addButton.size.height / 2.0 - 89.0)) .appear(.default(scale: true)) .disappear(.default(scale: true)) + .cornerRadius(12.0) ) let doneButton = doneButton.update( @@ -2224,9 +2225,9 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U return self._contentWrapperView! } - init(controller: DrawingScreen, context: AccountContext) { + init(controller: DrawingScreen) { self.controller = controller - self.context = context + self.context = controller.context self.updateState = ActionSlot() self.updateColor = ActionSlot() self.performAction = ActionSlot() @@ -2918,6 +2919,10 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U self.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait) } + required public init(coder: NSCoder) { + preconditionFailure() + } + public var drawingView: DrawingView { return self.node.drawingView } @@ -2934,12 +2939,8 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U return self.node.contentWrapperView } - required public init(coder: NSCoder) { - preconditionFailure() - } - override public func loadDisplayNode() { - self.displayNode = Node(controller: self, context: self.context) + self.displayNode = Node(controller: self) super.displayNodeDidLoad() @@ -2983,6 +2984,11 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U self.entitiesView.layer.render(in: context) }, opaque: false, scale: 1.0) + if #available(iOS 16.0, *) { + let path = NSTemporaryDirectory() + "img.jpg" + try? finalImage?.jpegData(compressionQuality: 0.9)?.write(to: URL(filePath: path)) + } + var image = paintingImage var stillImage: UIImage? if hasAnimatedEntities { @@ -3024,7 +3030,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { super.containerLayoutUpdated(layout, transition: transition) - (self.displayNode as! Node).containerLayoutUpdated(layout: layout, orientation: orientation, transition: Transition(transition)) + (self.displayNode as! Node).containerLayoutUpdated(layout: layout, orientation: self.orientation, transition: Transition(transition)) } public func adapterContainerLayoutUpdatedSize(_ size: CGSize, intrinsicInsets: UIEdgeInsets, safeInsets: UIEdgeInsets, statusBarHeight: CGFloat, inputHeight: CGFloat, orientation: UIInterfaceOrientation, isRegular: Bool, animated: Bool) { diff --git a/submodules/PremiumUI/BUILD b/submodules/PremiumUI/BUILD index 491ed7d2f3..f511297f9b 100644 --- a/submodules/PremiumUI/BUILD +++ b/submodules/PremiumUI/BUILD @@ -94,6 +94,7 @@ swift_library( "//submodules/Components/SheetComponent:SheetComponent", "//submodules/Components/BundleIconComponent:BundleIconComponent", "//submodules/Components/SolidRoundedButtonComponent:SolidRoundedButtonComponent", + "//submodules/Components/BlurredBackgroundComponent:BlurredBackgroundComponent", "//submodules/TelegramUI/Components/EmojiStatusComponent", "//submodules/TelegramUI/Components/AnimationCache:AnimationCache", "//submodules/TelegramUI/Components/MultiAnimationRenderer:MultiAnimationRenderer", diff --git a/submodules/PremiumUI/Sources/PremiumDemoScreen.swift b/submodules/PremiumUI/Sources/PremiumDemoScreen.swift index aa824e59ca..bf6f407549 100644 --- a/submodules/PremiumUI/Sources/PremiumDemoScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumDemoScreen.swift @@ -14,6 +14,7 @@ import SheetComponent import MultilineTextComponent import BundleIconComponent import SolidRoundedButtonComponent +import BlurredBackgroundComponent import Markdown import TelegramUIPreferences @@ -956,9 +957,8 @@ private final class DemoSheetContent: CombinedComponent { AnyComponentWithIdentity( id: "background", component: AnyComponent( - BlurredRectangle( - color: UIColor(rgb: 0x888888, alpha: 0.1), - radius: 15.0 + BlurredBackgroundComponent( + color: UIColor(rgb: 0x888888, alpha: 0.1) ) ) ), @@ -978,6 +978,8 @@ private final class DemoSheetContent: CombinedComponent { ) context.add(closeButton .position(CGPoint(x: context.availableSize.width - environment.safeInsets.left - closeButton.size.width, y: 28.0)) + .clipsToBounds(true) + .cornerRadius(15.0) ) let buttonText: String diff --git a/submodules/PremiumUI/Sources/PremiumGiftScreen.swift b/submodules/PremiumUI/Sources/PremiumGiftScreen.swift index 96ffb99c67..526d3149ac 100644 --- a/submodules/PremiumUI/Sources/PremiumGiftScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumGiftScreen.swift @@ -13,6 +13,7 @@ import SolidRoundedButtonComponent import MultilineTextComponent import BundleIconComponent import SolidRoundedButtonComponent +import BlurredBackgroundComponent import Markdown import InAppPurchaseManager import ConfettiEffect @@ -673,10 +674,10 @@ private final class PremiumGiftScreenComponent: CombinedComponent { let background = Child(Rectangle.self) let scrollContent = Child(ScrollComponent.self) let star = Child(GiftAvatarComponent.self) - let topPanel = Child(BlurredRectangle.self) + let topPanel = Child(BlurredBackgroundComponent.self) let topSeparator = Child(Rectangle.self) let title = Child(MultilineTextComponent.self) - let bottomPanel = Child(BlurredRectangle.self) + let bottomPanel = Child(BlurredBackgroundComponent.self) let bottomSeparator = Child(Rectangle.self) let button = Child(SolidRoundedButtonComponent.self) @@ -692,7 +693,7 @@ private final class PremiumGiftScreenComponent: CombinedComponent { } let topPanel = topPanel.update( - component: BlurredRectangle( + component: BlurredBackgroundComponent( color: environment.theme.rootController.navigationBar.blurredBackgroundColor ), availableSize: CGSize(width: context.availableSize.width, height: environment.navigationHeight), @@ -851,7 +852,7 @@ private final class PremiumGiftScreenComponent: CombinedComponent { transition: context.transition) let bottomPanel = bottomPanel.update( - component: BlurredRectangle( + component: BlurredBackgroundComponent( color: environment.theme.rootController.tabBar.backgroundColor ), availableSize: CGSize(width: context.availableSize.width, height: bottomPanelPadding + button.size.height + bottomInset), diff --git a/submodules/PremiumUI/Sources/PremiumIntroScreen.swift b/submodules/PremiumUI/Sources/PremiumIntroScreen.swift index c33bef1b67..d485e3e8bb 100644 --- a/submodules/PremiumUI/Sources/PremiumIntroScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumIntroScreen.swift @@ -14,6 +14,7 @@ import MultilineTextComponent import MultilineTextWithEntitiesComponent import BundleIconComponent import SolidRoundedButtonComponent +import BlurredBackgroundComponent import Markdown import InAppPurchaseManager import ConfettiEffect @@ -1915,58 +1916,6 @@ private final class PremiumIntroScreenContentComponent: CombinedComponent { } } -class BlurredRectangle: Component { - let color: UIColor - let radius: CGFloat - - init(color: UIColor, radius: CGFloat = 0.0) { - self.color = color - self.radius = radius - } - - static func ==(lhs: BlurredRectangle, rhs: BlurredRectangle) -> Bool { - if !lhs.color.isEqual(rhs.color) { - return false - } - if lhs.radius != rhs.radius { - return false - } - return true - } - - final class View: UIView { - private let background: NavigationBackgroundNode - - init() { - self.background = NavigationBackgroundNode(color: .clear) - - super.init(frame: CGRect()) - - self.addSubview(self.background.view) - } - - required init?(coder aDecoder: NSCoder) { - preconditionFailure() - } - - func update(component: BlurredRectangle, availableSize: CGSize, transition: Transition) -> CGSize { - transition.setFrame(view: self.background.view, frame: CGRect(origin: CGPoint(), size: availableSize)) - self.background.updateColor(color: component.color, transition: .immediate) - self.background.update(size: availableSize, cornerRadius: component.radius, transition: .immediate) - - return availableSize - } - } - - func makeView() -> View { - return View() - } - - func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: Transition) -> CGSize { - return view.update(component: self, availableSize: availableSize, transition: transition) - } -} - private final class PremiumIntroScreenComponent: CombinedComponent { typealias EnvironmentType = ViewControllerComponentContainer.Environment @@ -2298,11 +2247,11 @@ private final class PremiumIntroScreenComponent: CombinedComponent { let scrollContent = Child(ScrollComponent.self) let star = Child(PremiumStarComponent.self) let emoji = Child(EmojiHeaderComponent.self) - let topPanel = Child(BlurredRectangle.self) + let topPanel = Child(BlurredBackgroundComponent.self) let topSeparator = Child(Rectangle.self) let title = Child(MultilineTextComponent.self) let secondaryTitle = Child(MultilineTextWithEntitiesComponent.self) - let bottomPanel = Child(BlurredRectangle.self) + let bottomPanel = Child(BlurredBackgroundComponent.self) let bottomSeparator = Child(Rectangle.self) let button = Child(SolidRoundedButtonComponent.self) @@ -2351,7 +2300,7 @@ private final class PremiumIntroScreenComponent: CombinedComponent { } let topPanel = topPanel.update( - component: BlurredRectangle( + component: BlurredBackgroundComponent( color: environment.theme.rootController.navigationBar.blurredBackgroundColor ), availableSize: CGSize(width: context.availableSize.width, height: environment.navigationHeight), @@ -2670,7 +2619,7 @@ private final class PremiumIntroScreenComponent: CombinedComponent { transition: context.transition) let bottomPanel = bottomPanel.update( - component: BlurredRectangle( + component: BlurredBackgroundComponent( color: environment.theme.rootController.tabBar.backgroundColor ), availableSize: CGSize(width: context.availableSize.width, height: bottomPanelPadding + button.size.height + bottomInset), diff --git a/submodules/PremiumUI/Sources/PremiumLimitsListScreen.swift b/submodules/PremiumUI/Sources/PremiumLimitsListScreen.swift index 4ed0387240..b85422c728 100644 --- a/submodules/PremiumUI/Sources/PremiumLimitsListScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumLimitsListScreen.swift @@ -15,6 +15,7 @@ import MultilineTextComponent import BundleIconComponent import Markdown import SolidRoundedButtonNode +import BlurredBackgroundComponent private final class LimitComponent: CombinedComponent { let title: String @@ -487,7 +488,7 @@ private final class LimitsPageComponent: CombinedComponent { static var body: Body { let background = Child(Rectangle.self) let scroll = Child(ScrollComponent.self) - let topPanel = Child(BlurredRectangle.self) + let topPanel = Child(BlurredBackgroundComponent.self) let topSeparator = Child(Rectangle.self) let title = Child(MultilineTextComponent.self) @@ -544,7 +545,7 @@ private final class LimitsPageComponent: CombinedComponent { ) let topPanel = topPanel.update( - component: BlurredRectangle( + component: BlurredBackgroundComponent( color: theme.rootController.navigationBar.blurredBackgroundColor ), availableSize: CGSize(width: context.availableSize.width, height: topInset), @@ -1253,9 +1254,8 @@ public class PremiumLimitsListScreen: ViewController { AnyComponentWithIdentity( id: "background", component: AnyComponent( - BlurredRectangle( - color: UIColor(rgb: 0x888888, alpha: 0.3), - radius: 15.0 + BlurredBackgroundComponent( + color: UIColor(rgb: 0x888888, alpha: 0.3) ) ) ), @@ -1274,6 +1274,8 @@ public class PremiumLimitsListScreen: ViewController { environment: {}, containerSize: CGSize(width: 30.0, height: 30.0) ) + self.closeView.clipsToBounds = true + self.closeView.layer.cornerRadius = 15.0 self.closeView.frame = CGRect(origin: CGPoint(x: contentSize.width - closeSize.width * 1.5, y: 28.0 - closeSize.height / 2.0), size: closeSize) } private var cachedCloseImage: UIImage?