From 9f2e9407efff968e7fe9dee8f2da1cc436c1fd0c Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 11 Aug 2023 21:19:22 +0200 Subject: [PATCH 1/2] Various fixes --- .../Sources/AccountContext.swift | 2 +- .../Sources/VenueIconResources.swift | 15 +- .../Sources/LocationActionListItem.swift | 44 +++-- .../LocationPickerControllerNode.swift | 16 +- .../Sources/MediaPickerGridItem.swift | 4 + .../Sources/MediaPickerScreen.swift | 179 +++++++++++------- .../Sources/MediaPickerTitleView.swift | 1 + .../CameraScreen/Sources/CameraScreen.swift | 2 + .../Sources/MediaEditorScreen.swift | 1 + .../Sources/SharedAccountContext.swift | 4 +- 10 files changed, 173 insertions(+), 95 deletions(-) diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index b87c7bab5dd..cf91a69342f 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -902,7 +902,7 @@ public protocol SharedAccountContext: AnyObject { func makeMediaPickerScreen(context: AccountContext, hasSearch: Bool, completion: @escaping (Any) -> Void) -> ViewController - func makeStoryMediaPickerScreen(context: AccountContext, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, dismissed: @escaping () -> Void) -> ViewController + func makeStoryMediaPickerScreen(context: AccountContext, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, dismissed: @escaping () -> Void, groupsPresented: @escaping () -> Void) -> ViewController func makeProxySettingsController(sharedContext: SharedAccountContext, account: UnauthorizedAccount) -> ViewController diff --git a/submodules/LocationResources/Sources/VenueIconResources.swift b/submodules/LocationResources/Sources/VenueIconResources.swift index 47f1fc2d2d1..09d0dc09485 100644 --- a/submodules/LocationResources/Sources/VenueIconResources.swift +++ b/submodules/LocationResources/Sources/VenueIconResources.swift @@ -135,7 +135,7 @@ public struct VenueIconArguments: TransformImageCustomArguments { } public func venueIcon(engine: TelegramEngine, type: String, flag: String? = nil, background: Bool) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> { - let isBuiltinIcon = ["", "home", "work"].contains(type) + let isBuiltinIcon = ["", "home", "work"].contains(type) || flag != nil let data: Signal = isBuiltinIcon ? .single(nil) : venueIconData(engine: engine, resource: VenueIconResource(type: type)) return data |> map { data in return { arguments in @@ -164,7 +164,18 @@ public func venueIcon(engine: TelegramEngine, type: String, flag: String? = nil, c.fillEllipse(in: CGRect(origin: CGPoint(), size: arguments.drawingRect.size)) } let boundsSize = CGSize(width: arguments.drawingRect.size.width - 4.0 * 2.0, height: arguments.drawingRect.size.height - 4.0 * 2.0) - if let image = iconImage, let cgImage = generateTintedImage(image: image, color: foregroundColor)?.cgImage { + if let flag { + let attributedString = NSAttributedString(string: flag, attributes: [NSAttributedString.Key.font: Font.regular(22.0), NSAttributedString.Key.foregroundColor: UIColor.white]) + + let line = CTLineCreateWithAttributedString(attributedString) + let lineBounds = CTLineGetBoundsWithOptions(line, .useGlyphPathBounds) + + let bounds = CGRect(origin: .zero, size: boundsSize) + let lineOrigin = CGPoint(x: floorToScreenPixels((bounds.size.width - lineBounds.size.width) / 2.0), y: floorToScreenPixels((bounds.size.height - lineBounds.size.height) / 2.0)) + + c.translateBy(x: lineOrigin.x + 3.0, y: lineOrigin.y + 7.0) + CTLineDraw(line, c) + } else if let image = iconImage, let cgImage = generateTintedImage(image: image, color: foregroundColor)?.cgImage { let fittedSize = image.size.aspectFitted(boundsSize) c.draw(cgImage, in: CGRect(origin: CGPoint(x: floor((arguments.drawingRect.width - fittedSize.width) / 2.0), y: floor((arguments.drawingRect.height - fittedSize.height) / 2.0)), size: fittedSize)) } else if isBuiltinIcon { diff --git a/submodules/LocationUI/Sources/LocationActionListItem.swift b/submodules/LocationUI/Sources/LocationActionListItem.swift index a55ab08c8e9..9a838c35d8a 100644 --- a/submodules/LocationUI/Sources/LocationActionListItem.swift +++ b/submodules/LocationUI/Sources/LocationActionListItem.swift @@ -268,22 +268,36 @@ final class LocationActionListItemNode: ListViewItemNode { var arguments: TransformImageCustomArguments? if let updatedIcon = updatedIcon { switch updatedIcon { - case .location: - strongSelf.iconNode.isHidden = false - strongSelf.venueIconNode.isHidden = true - strongSelf.iconNode.image = generateLocationIcon(theme: item.presentationData.theme) - case .liveLocation, .stopLiveLocation: - strongSelf.iconNode.isHidden = false - strongSelf.venueIconNode.isHidden = true - strongSelf.iconNode.image = generateLiveLocationIcon(theme: item.presentationData.theme, stop: updatedIcon == .stopLiveLocation) - case let .venue(venue): - strongSelf.iconNode.isHidden = true - strongSelf.venueIconNode.isHidden = false - strongSelf.venueIconNode.setSignal(venueIcon(engine: item.engine, type: venue.venue?.type ?? "", background: true)) - - if venue.venue?.id == "city" { - arguments = VenueIconArguments(defaultBackgroundColor: item.presentationData.theme.chat.inputPanel.actionControlFillColor, defaultForegroundColor: .white) + case .location: + strongSelf.iconNode.isHidden = false + strongSelf.venueIconNode.isHidden = true + strongSelf.iconNode.image = generateLocationIcon(theme: item.presentationData.theme) + case .liveLocation, .stopLiveLocation: + strongSelf.iconNode.isHidden = false + strongSelf.venueIconNode.isHidden = true + strongSelf.iconNode.image = generateLiveLocationIcon(theme: item.presentationData.theme, stop: updatedIcon == .stopLiveLocation) + case let .venue(venue): + strongSelf.iconNode.isHidden = true + strongSelf.venueIconNode.isHidden = false + + func flagEmoji(countryCode: String) -> String { + let base : UInt32 = 127397 + var flagString = "" + for v in countryCode.uppercased().unicodeScalars { + flagString.unicodeScalars.append(UnicodeScalar(base + v.value)!) } + return flagString + } + let type = venue.venue?.type + var flag: String? + if let venue = venue.venue, venue.provider == "city", let countryCode = venue.id { + flag = flagEmoji(countryCode: countryCode) + } + + if venue.venue?.provider == "city" { + arguments = VenueIconArguments(defaultBackgroundColor: item.presentationData.theme.chat.inputPanel.actionControlFillColor, defaultForegroundColor: .white) + } + strongSelf.venueIconNode.setSignal(venueIcon(engine: item.engine, type: type ?? "", flag: flag, background: true)) } if updatedIcon == .stopLiveLocation { diff --git a/submodules/LocationUI/Sources/LocationPickerControllerNode.swift b/submodules/LocationUI/Sources/LocationPickerControllerNode.swift index 1f17d5f4baa..de571851592 100644 --- a/submodules/LocationUI/Sources/LocationPickerControllerNode.swift +++ b/submodules/LocationUI/Sources/LocationPickerControllerNode.swift @@ -150,7 +150,7 @@ private enum LocationPickerEntry: Comparable, Identifiable { case let .city(_, title, subtitle, _, _, _, coordinate, name, countryCode): let icon: LocationActionListItemIcon if let name { - icon = .venue(TelegramMediaMap(latitude: 0, longitude: 0, heading: nil, accuracyRadius: nil, geoPlace: nil, venue: MapVenue(title: name, address: "City", provider: nil, id: "city", type: "building/default"), liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil)) + icon = .venue(TelegramMediaMap(latitude: 0, longitude: 0, heading: nil, accuracyRadius: nil, geoPlace: nil, venue: MapVenue(title: name, address: presentationData.strings.Location_TypeCity, provider: "city", id: countryCode, type: "building/default"), liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil)) } else { icon = .location } @@ -583,20 +583,28 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM switch strongSelf.mode { case .share: if source == .story { - title = "Add This Location" + title = presentationData.strings.Location_AddThisLocation } else { title = presentationData.strings.Map_SendThisLocation } case .pick: title = presentationData.strings.Map_SetThisLocation } - entries.append(.location(presentationData.theme, title, address ?? presentationData.strings.Map_Locating, nil, nil, nil, coordinate, state.street, state.countryCode, true)) + if source == .story { + if state.street != "" { + entries.append(.location(presentationData.theme, state.street ?? presentationData.strings.Map_Locating, state.isStreet ? presentationData.strings.Location_TypeStreet : presentationData.strings.Location_TypeLocation, nil, nil, nil, coordinate, state.street, nil, false)) + } else if state.city != "" { + entries.append(.city(presentationData.theme, state.city ?? presentationData.strings.Map_Locating, presentationData.strings.Location_TypeCity, nil, nil, nil, coordinate, state.city, state.countryCode)) + } + } else { + entries.append(.location(presentationData.theme, title, address ?? presentationData.strings.Map_Locating, nil, nil, nil, coordinate, state.street, nil, true)) + } case .selecting: let title: String switch strongSelf.mode { case .share: if source == .story { - title = "Add This Location" + title = presentationData.strings.Location_AddThisLocation } else { title = presentationData.strings.Map_SendThisLocation } diff --git a/submodules/MediaPickerUI/Sources/MediaPickerGridItem.swift b/submodules/MediaPickerUI/Sources/MediaPickerGridItem.swift index f6b688fbbd0..e947302ed56 100644 --- a/submodules/MediaPickerUI/Sources/MediaPickerGridItem.swift +++ b/submodules/MediaPickerUI/Sources/MediaPickerGridItem.swift @@ -309,6 +309,9 @@ final class MediaPickerGridItemNode: GridItemNode { self.progressDisposable.set(nil) self.updateProgress(nil, animated: false) + + self.backgroundNode.image = nil + self.imageNode.contentMode = .scaleAspectFill } if self.draftNode.supernode == nil { @@ -403,6 +406,7 @@ final class MediaPickerGridItemNode: GridItemNode { if asset.localIdentifier == self.currentAsset?.localIdentifier { return } + self.backgroundNode.image = nil self.progressDisposable.set( (interaction.downloadManager.downloadProgress(identifier: asset.localIdentifier) diff --git a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift index 174d9a67c63..57b98d389e3 100644 --- a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift +++ b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift @@ -73,7 +73,7 @@ private struct MediaPickerGridTransaction { let scrollToItem: GridNodeScrollToItem? init(previousList: [MediaPickerGridEntry], list: [MediaPickerGridEntry], context: AccountContext, interaction: MediaPickerInteraction, theme: PresentationTheme, strings: PresentationStrings, scrollToItem: GridNodeScrollToItem?) { - let (deleteIndices, indicesAndItems, updateIndices) = mergeListsStableWithUpdates(leftList: previousList, rightList: list) + let (deleteIndices, indicesAndItems, updateIndices) = mergeListsStableWithUpdates(leftList: previousList, rightList: list) self.deletions = deleteIndices self.insertions = indicesAndItems.map { GridNodeInsertItem(index: $0.0, item: $0.1.item(context: context, interaction: interaction, theme: theme, strings: strings), previousIndex: $0.2) } @@ -81,6 +81,19 @@ private struct MediaPickerGridTransaction { self.scrollToItem = scrollToItem } + + init(clearList: [MediaPickerGridEntry]) { + var deletions: [Int] = [] + var i = 0 + for _ in clearList { + deletions.append(i) + i += 1 + } + self.deletions = deletions + self.insertions = [] + self.updates = [] + self.scrollToItem = nil + } } struct Month: Equatable { @@ -585,6 +598,7 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { ) } + fileprivate var resetOnUpdate = false private func updateState(_ state: State) { guard let controller = self.controller, let interaction = controller.interaction else { return @@ -659,6 +673,69 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { self.requestedCameraAccess = true self.mediaAssetsContext.requestCameraAccess() } + + if !controller.didSetupGroups { + controller.didSetupGroups = true + controller.groupsPromise.set( + combineLatest( + self.mediaAssetsContext.fetchAssetsCollections(.album), + self.mediaAssetsContext.fetchAssetsCollections(.smartAlbum) + ) + |> map { albums, smartAlbums -> [MediaGroupItem] in + var collections: [PHAssetCollection] = [] + smartAlbums.enumerateObjects { collection, _, _ in + if [.smartAlbumUserLibrary, .smartAlbumFavorites].contains(collection.assetCollectionSubtype) { + collections.append(collection) + } + } + smartAlbums.enumerateObjects { collection, index, _ in + var supportedAlbums: [PHAssetCollectionSubtype] = [ + .smartAlbumBursts, + .smartAlbumPanoramas, + .smartAlbumScreenshots, + .smartAlbumSelfPortraits, + .smartAlbumSlomoVideos, + .smartAlbumTimelapses, + .smartAlbumVideos, + .smartAlbumAllHidden + ] + if #available(iOS 11, *) { + supportedAlbums.append(.smartAlbumAnimated) + supportedAlbums.append(.smartAlbumDepthEffect) + supportedAlbums.append(.smartAlbumLivePhotos) + } + if supportedAlbums.contains(collection.assetCollectionSubtype) { + let result = PHAsset.fetchAssets(in: collection, options: nil) + if result.count > 0 { + collections.append(collection) + } + } + } + albums.enumerateObjects(options: [.reverse]) { collection, _, _ in + collections.append(collection) + } + + var items: [MediaGroupItem] = [] + for collection in collections { + let result = PHAsset.fetchAssets(in: collection, options: nil) + let firstItem: PHAsset? + if [.smartAlbumUserLibrary, .smartAlbumFavorites].contains(collection.assetCollectionSubtype) { + firstItem = result.lastObject + } else { + firstItem = result.firstObject + } + items.append( + MediaGroupItem( + collection: collection, + firstItem: firstItem, + count: result.count + ) + ) + } + return items + } + ) + } } else if case .notDetermined = mediaAccess, !self.requestedMediaAccess { self.requestedMediaAccess = true self.mediaAssetsContext.requestMediaAccess() @@ -671,7 +748,16 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { } } - let previousEntries = self.currentEntries + + + var previousEntries = self.currentEntries + + if self.resetOnUpdate { + self.enqueueTransaction(MediaPickerGridTransaction(clearList: previousEntries)) + self.resetOnUpdate = false + previousEntries = [] + } + self.currentEntries = entries var scrollToItem: GridNodeScrollToItem? @@ -692,6 +778,10 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { self.updateNavigation(transition: .immediate) } + private func resetItems() { + + } + private func updateSelectionState(animated: Bool = false) { self.gridNode.forEachItemNode { itemNode in if let itemNode = itemNode as? MediaPickerGridItemNode { @@ -1541,7 +1631,7 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { self.titleView.action = { [weak self] in if let self { - self.openGroupsMenu() + self.presentGroupsMenu() } } @@ -1720,77 +1810,20 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { self.controllerNode.closeGalleryController() } - public func openGroupsMenu() { - let updatedState = combineLatest( - queue: Queue.mainQueue(), - self.controllerNode.mediaAssetsContext.fetchAssetsCollections(.album), - self.controllerNode.mediaAssetsContext.fetchAssetsCollections(.smartAlbum) - ) - let _ = (updatedState + public var groupsPresented: () -> Void = {} + + private var didSetupGroups = false + private let groupsPromise = Promise<[MediaGroupItem]>() + + public func presentGroupsMenu() { + self.groupsPresented() + + let _ = (self.groupsPromise.get() |> take(1) - |> deliverOnMainQueue).start(next: { [weak self] albums, smartAlbums in + |> deliverOnMainQueue).start(next: { [weak self] items in guard let self else { return } - - var collections: [PHAssetCollection] = [] - smartAlbums.enumerateObjects { collection, _, _ in - if [.smartAlbumUserLibrary, .smartAlbumFavorites].contains(collection.assetCollectionSubtype) { - collections.append(collection) - } - } - smartAlbums.enumerateObjects { collection, index, _ in - var supportedAlbums: [PHAssetCollectionSubtype] = [ - .smartAlbumBursts, - .smartAlbumPanoramas, - .smartAlbumScreenshots, - .smartAlbumSelfPortraits, - .smartAlbumSlomoVideos, - .smartAlbumTimelapses, - .smartAlbumVideos, - .smartAlbumAllHidden - ] - if #available(iOS 11, *) { - supportedAlbums.append(.smartAlbumAnimated) - supportedAlbums.append(.smartAlbumDepthEffect) - supportedAlbums.append(.smartAlbumLivePhotos) - } - if supportedAlbums.contains(collection.assetCollectionSubtype) { - let result = PHAsset.fetchAssets(in: collection, options: nil) - if result.count > 0 { - collections.append(collection) - } - } - } - albums.enumerateObjects(options: [.reverse]) { collection, _, _ in - collections.append(collection) - } - - var items: [MediaGroupItem] = [] - for collection in collections { - let result = PHAsset.fetchAssets(in: collection, options: nil) - let firstItem: PHAsset? - if [.smartAlbumUserLibrary, .smartAlbumFavorites].contains(collection.assetCollectionSubtype) { - firstItem = result.lastObject - } else { - firstItem = result.firstObject - } -// let iconSource: ContextMenuActionItemIconSource? -// if let firstItem { -// let targetSize = CGSize(width: 24.0, height: 24.0) -// iconSource = ContextMenuActionItemIconSource(size: CGSize(width: 24.0, height: 24.0), contentMode: .scaleAspectFill, cornerRadius: 6.0, signal: assetImage(asset: firstItem, targetSize: targetSize, exact: false)) -// } else { -// iconSource = nil -// } - items.append( - MediaGroupItem( - collection: collection, - firstItem: firstItem, - count: result.count - ) - ) - } - var dismissImpl: (() -> Void)? let content: ContextControllerItemsContent = MediaGroupsContextMenuContent( context: self.context, @@ -1799,6 +1832,7 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { guard let self else { return } + self.controllerNode.resetOnUpdate = true if collection.assetCollectionSubtype == .smartAlbumUserLibrary { self.selectedCollection.set(.single(nil)) self.titleView.title = self.presentationData.strings.MediaPicker_Recents @@ -1806,6 +1840,7 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { self.selectedCollection.set(.single(collection)) self.titleView.title = collection.localizedTitle ?? "" } + self.scrollToTop?() dismissImpl?() } ) @@ -2461,7 +2496,8 @@ public func storyMediaPickerController( context: AccountContext, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, - dismissed: @escaping () -> Void + dismissed: @escaping () -> Void, + groupsPresented: @escaping () -> Void ) -> ViewController { let presentationData = context.sharedContext.currentPresentationData.with({ $0 }).withUpdated(theme: defaultDarkColorPresentationTheme) let updatedPresentationData: (PresentationData, Signal) = (presentationData, .single(presentationData)) @@ -2472,6 +2508,7 @@ public func storyMediaPickerController( controller.getSourceRect = getSourceRect controller.requestController = { _, present in let mediaPickerController = MediaPickerScreen(context: context, updatedPresentationData: updatedPresentationData, peer: nil, threadTitle: nil, chatLocation: nil, bannedSendPhotos: nil, bannedSendVideos: nil, subject: .assets(nil, .story), mainButtonState: nil, mainButtonAction: nil) + mediaPickerController.groupsPresented = groupsPresented mediaPickerController.customSelection = { controller, result in if let result = result as? MediaEditorDraft { controller.updateHiddenMediaId(result.path) diff --git a/submodules/MediaPickerUI/Sources/MediaPickerTitleView.swift b/submodules/MediaPickerUI/Sources/MediaPickerTitleView.swift index 20543c5443b..eb42c6da287 100644 --- a/submodules/MediaPickerUI/Sources/MediaPickerTitleView.swift +++ b/submodules/MediaPickerUI/Sources/MediaPickerTitleView.swift @@ -47,6 +47,7 @@ final class MediaPickerTitleView: UIView { if self.segmentsHidden != oldValue { let transition = ContainedViewLayoutTransition.animated(duration: 0.21, curve: .easeInOut) transition.updateAlpha(node: self.titleNode, alpha: self.segmentsHidden ? 1.0 : 0.0) + transition.updateAlpha(node: self.arrowNode, alpha: self.segmentsHidden ? 1.0 : 0.0) transition.updateAlpha(node: self.segmentedControlNode, alpha: self.segmentsHidden ? 0.0 : 1.0) self.segmentedControlNode.isUserInteractionEnabled = !self.segmentsHidden } diff --git a/submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift b/submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift index 49e27803dcd..3b1f0ef4652 100644 --- a/submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift +++ b/submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift @@ -2577,6 +2577,8 @@ public class CameraScreen: ViewController { self.node.hasGallery = false self.node.requestUpdateLayout(hasAppeared: self.node.hasAppeared, transition: .immediate) } + }, groupsPresented: { + stopCameraCapture() }) self.galleryController = controller } diff --git a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift index 58ec4361f8b..a030a7852bd 100644 --- a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift +++ b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift @@ -2068,6 +2068,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate self.isInteractingWithEntities = isInteracting if !isInteracting { self.controller?.isSavingAvailable = true + self.hasAnyChanges = true } self.requestUpdate(transition: .easeInOut(duration: 0.2)) } diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 26c6f7e7d94..9fdc0e3ac14 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -1869,8 +1869,8 @@ public final class SharedAccountContextImpl: SharedAccountContext { return mediaPickerController(context: context, hasSearch: hasSearch, completion: completion) } - public func makeStoryMediaPickerScreen(context: AccountContext, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, dismissed: @escaping () -> Void) -> ViewController { - return storyMediaPickerController(context: context, getSourceRect: getSourceRect, completion: completion, dismissed: dismissed) + public func makeStoryMediaPickerScreen(context: AccountContext, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, dismissed: @escaping () -> Void, groupsPresented: @escaping () -> Void) -> ViewController { + return storyMediaPickerController(context: context, getSourceRect: getSourceRect, completion: completion, dismissed: dismissed, groupsPresented: groupsPresented) } public func makeProxySettingsController(sharedContext: SharedAccountContext, account: UnauthorizedAccount) -> ViewController { From d4408c2bb03d9ae43afc9755d0e9835f978e011c Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 11 Aug 2023 21:43:20 +0200 Subject: [PATCH 2/2] Various fixes --- .../StoryItemSetContainerComponent.swift | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift index fa11aad94cf..6061714ea91 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift @@ -854,6 +854,7 @@ public final class StoryItemSetContainerComponent: Component { @objc private func tapGesture(_ recognizer: UITapGestureRecognizer) { if case .ended = recognizer.state, let component = self.component, let itemLayout = self.itemLayout { + if let _ = self.sendMessageContext.menuController { return } @@ -896,26 +897,29 @@ public final class StoryItemSetContainerComponent: Component { } else { let referenceSize = self.controlsContainerView.frame.size let point = recognizer.location(in: self.controlsContainerView) - + var selectedMediaArea: MediaArea? - - func isPoint(_ point: CGPoint, in area: MediaArea) -> Bool { - let tx = point.x - area.coordinates.x / 100.0 * referenceSize.width - let ty = point.y - area.coordinates.y / 100.0 * referenceSize.height - - let rad = -area.coordinates.rotation * Double.pi / 180.0 - let cosTheta = cos(rad) - let sinTheta = sin(rad) - let rotatedX = tx * cosTheta - ty * sinTheta - let rotatedY = tx * sinTheta + ty * cosTheta - - return abs(rotatedX) <= area.coordinates.width / 100.0 * referenceSize.width / 2.0 * 1.1 && abs(rotatedY) <= area.coordinates.height / 100.0 * referenceSize.height / 2.0 * 1.1 - } - for area in component.slice.item.storyItem.mediaAreas { - if isPoint(point, in: area) { - selectedMediaArea = area - break + let safeAreaInset: CGFloat = 48.0 + if point.x > safeAreaInset && point.x < referenceSize.width - safeAreaInset { + func isPoint(_ point: CGPoint, in area: MediaArea) -> Bool { + let tx = point.x - area.coordinates.x / 100.0 * referenceSize.width + let ty = point.y - area.coordinates.y / 100.0 * referenceSize.height + + let rad = -area.coordinates.rotation * Double.pi / 180.0 + let cosTheta = cos(rad) + let sinTheta = sin(rad) + let rotatedX = tx * cosTheta - ty * sinTheta + let rotatedY = tx * sinTheta + ty * cosTheta + + return abs(rotatedX) <= area.coordinates.width / 100.0 * referenceSize.width / 2.0 * 1.1 && abs(rotatedY) <= area.coordinates.height / 100.0 * referenceSize.height / 2.0 * 1.1 + } + + for area in component.slice.item.storyItem.mediaAreas { + if isPoint(point, in: area) { + selectedMediaArea = area + break + } } }