Avatar editor fixes

This commit is contained in:
Ilya Laktyushin 2023-01-22 16:14:46 +04:00
parent 3f70f73f1c
commit 11d2a68cd1
9 changed files with 58 additions and 23 deletions

View File

@ -370,6 +370,7 @@ class StickerPickerScreen: ViewController {
updateScrollingToItemGroup: { [weak self] in
self?.update(isExpanded: true, transition: .animated(duration: 0.4, curve: .spring))
},
onScroll: {},
chatPeerId: nil,
peekBehavior: nil,
customLayout: nil,
@ -447,6 +448,7 @@ class StickerPickerScreen: ViewController {
updateScrollingToItemGroup: { [weak self] in
self?.update(isExpanded: true, transition: .animated(duration: 0.4, curve: .spring))
},
onScroll: {},
chatPeerId: nil,
peekBehavior: nil,
customLayout: nil,
@ -571,6 +573,7 @@ class StickerPickerScreen: ViewController {
updateScrollingToItemGroup: { [weak self] in
self?.update(isExpanded: true, transition: .animated(duration: 0.4, curve: .spring))
},
onScroll: {},
chatPeerId: nil,
peekBehavior: stickerPeekBehavior,
customLayout: nil,

View File

@ -1513,6 +1513,7 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
},
updateScrollingToItemGroup: {
},
onScroll: {},
chatPeerId: nil,
peekBehavior: nil,
customLayout: emojiContentLayout,

View File

@ -577,6 +577,12 @@ final class AvatarEditorScreenComponent: Component {
},
updateScrollingToItemGroup: {
},
onScroll: { [weak self] in
if let self, let state = self.state, state.expanded {
state.expanded = false
state.updated(transition: Transition(animation: .curve(duration: 0.45, curve: .spring)))
}
},
chatPeerId: nil,
peekBehavior: nil,
customLayout: nil,
@ -586,18 +592,6 @@ final class AvatarEditorScreenComponent: Component {
hideBackground: true
)
// var stickerPeekBehavior: EmojiContentPeekBehaviorImpl?
// if let controller = self.controller {
// stickerPeekBehavior = EmojiContentPeekBehaviorImpl(
// context: controller.context,
// interaction: nil,
// chatPeerId: nil,
// present: { [weak controller] c, a in
// controller?.presentInGlobalOverlay(c, with: a)
// }
// )
// }
data.stickers?.inputInteractionHolder.inputInteraction = EmojiPagerContentComponent.InputInteraction(
performItemAction: { [weak self] _, item, _, _, _, _ in
guard let self, let _ = item.itemFile else {
@ -707,6 +701,12 @@ final class AvatarEditorScreenComponent: Component {
},
updateScrollingToItemGroup: {
},
onScroll: { [weak self] in
if let self, let state = self.state, state.expanded {
state.expanded = false
state.updated(transition: Transition(animation: .curve(duration: 0.45, curve: .spring)))
}
},
chatPeerId: nil,
peekBehavior: nil,
customLayout: nil,
@ -747,10 +747,12 @@ final class AvatarEditorScreenComponent: Component {
}
}
let backgroundIsBright = UIColor(rgb: state.selectedBackground.colors.first ?? 0).lightness > 0.8
let navigationCancelButtonSize = self.navigationCancelButton.update(
transition: transition,
component: AnyComponent(Button(
content: AnyComponent(Text(text: environment.strings.Common_Cancel, font: Font.regular(17.0), color: state.expanded ? .white : environment.theme.rootController.navigationBar.accentTextColor)),
content: AnyComponent(Text(text: environment.strings.Common_Cancel, font: Font.regular(17.0), color: state.expanded && !backgroundIsBright ? .white : environment.theme.rootController.navigationBar.accentTextColor)),
action: { [weak self] in
guard let self else {
return
@ -772,7 +774,7 @@ final class AvatarEditorScreenComponent: Component {
let navigationDoneButtonSize = self.navigationDoneButton.update(
transition: transition,
component: AnyComponent(Button(
content: AnyComponent(Text(text: strings.AvatarEditor_Set, font: Font.semibold(17.0), color: state.isSearchActive ? environment.theme.rootController.navigationBar.accentTextColor : .white)),
content: AnyComponent(Text(text: strings.AvatarEditor_Set, font: Font.semibold(17.0), color: state.isSearchActive || (state.expanded && backgroundIsBright) ? environment.theme.rootController.navigationBar.accentTextColor : .white)),
action: { [weak self] in
guard let self else {
return
@ -841,8 +843,13 @@ final class AvatarEditorScreenComponent: Component {
context: component.context,
background: state.selectedBackground,
file: state.selectedFile,
tapped: { [weak state] in
tapped: { [weak state, weak self] in
if let state, !state.editingColor {
if let emojiView = self?.keyboardView.findTaggedView(tag: EmojiPagerContentComponent.Tag(id: AnyHashable("emoji"))) as? EmojiPagerContentComponent.View {
emojiView.ensureSearchUnfocused()
} else if let emojiView = self?.keyboardView.findTaggedView(tag: EmojiPagerContentComponent.Tag(id: AnyHashable("stickers"))) as? EmojiPagerContentComponent.View {
emojiView.ensureSearchUnfocused()
}
state.expanded = !state.expanded
state.updated(transition: Transition(animation: .curve(duration: 0.35, curve: .spring)))
}

View File

@ -1084,6 +1084,7 @@ public final class ChatEntityKeyboardInputNode: ChatInputNode {
},
updateScrollingToItemGroup: {
},
onScroll: {},
chatPeerId: chatPeerId,
peekBehavior: stickerPeekBehavior,
customLayout: nil,
@ -1348,6 +1349,7 @@ public final class ChatEntityKeyboardInputNode: ChatInputNode {
},
updateScrollingToItemGroup: {
},
onScroll: {},
chatPeerId: chatPeerId,
peekBehavior: stickerPeekBehavior,
customLayout: nil,
@ -2168,6 +2170,7 @@ public final class EntityInputView: UIInputView, AttachmentTextInputPanelInputVi
},
updateScrollingToItemGroup: {
},
onScroll: {},
chatPeerId: nil,
peekBehavior: nil,
customLayout: nil,

View File

@ -610,6 +610,7 @@ public final class EmojiStatusSelectionController: ViewController {
},
updateScrollingToItemGroup: {
},
onScroll: {},
chatPeerId: nil,
peekBehavior: nil,
customLayout: nil,

View File

@ -2248,6 +2248,7 @@ public final class EmojiPagerContentComponent: Component {
public let requestUpdate: (Transition) -> Void
public let updateSearchQuery: (EmojiPagerContentComponent.SearchQuery?) -> Void
public let updateScrollingToItemGroup: () -> Void
public let onScroll: () -> Void
public let chatPeerId: PeerId?
public let peekBehavior: EmojiContentPeekBehavior?
public let customLayout: CustomLayout?
@ -2271,6 +2272,7 @@ public final class EmojiPagerContentComponent: Component {
requestUpdate: @escaping (Transition) -> Void,
updateSearchQuery: @escaping (SearchQuery?) -> Void,
updateScrollingToItemGroup: @escaping () -> Void,
onScroll: @escaping () -> Void,
chatPeerId: PeerId?,
peekBehavior: EmojiContentPeekBehavior?,
customLayout: CustomLayout?,
@ -2293,6 +2295,7 @@ public final class EmojiPagerContentComponent: Component {
self.requestUpdate = requestUpdate
self.updateSearchQuery = updateSearchQuery
self.updateScrollingToItemGroup = updateScrollingToItemGroup
self.onScroll = onScroll
self.chatPeerId = chatPeerId
self.peekBehavior = peekBehavior
self.customLayout = customLayout
@ -5007,6 +5010,14 @@ public final class EmojiPagerContentComponent: Component {
}
}
public func ensureSearchUnfocused() {
if self.isSearchActivated, let visibleSearchHeader = self.visibleSearchHeader, visibleSearchHeader.currentPresetSearchTerm == nil {
self.visibleSearchHeader?.deactivate()
} else {
self.visibleSearchHeader?.endEditing(true)
}
}
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
if self.ignoreScrolling {
return
@ -5019,6 +5030,7 @@ public final class EmojiPagerContentComponent: Component {
if self.isSearchActivated, let visibleSearchHeader = self.visibleSearchHeader, visibleSearchHeader.currentPresetSearchTerm == nil {
self.visibleSearchHeader?.deactivate()
}
self.component?.inputInteractionHolder.inputInteraction?.onScroll()
}
public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

View File

@ -969,6 +969,7 @@ private final class ForumCreateTopicScreenComponent: CombinedComponent {
},
updateScrollingToItemGroup: {
},
onScroll: {},
chatPeerId: nil,
peekBehavior: nil,
customLayout: nil,

View File

@ -6727,18 +6727,22 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
let isPremium = self.context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.Peer(id: self.context.account.peerId))
|> map { peer -> Bool in
return peer?.isPremium ?? false
}
self.translationStateDisposable = (combineLatest(
queue: .concurrentDefaultQueue(),
isPremium,
self.chatDisplayNode.historyNode.cachedPeerDataAndMessages
) |> mapToSignal { isPremium, cachedDataAndMessages -> Signal<ChatPresentationTranslationState?, NoError> in
} |> distinctUntilChanged
let isHidden = self.chatDisplayNode.historyNode.cachedPeerDataAndMessages
|> map { cachedDataAndMessages -> Bool in
let (cachedData, _) = cachedDataAndMessages
var isHidden = false
if let cachedData = cachedData as? CachedChannelData, cachedData.flags.contains(.translationHidden) {
isHidden = true
}
return isHidden
} |> distinctUntilChanged
self.translationStateDisposable = (combineLatest(
queue: .concurrentDefaultQueue(),
isPremium,
isHidden
) |> mapToSignal { isPremium, isHidden -> Signal<ChatPresentationTranslationState?, NoError> in
if isPremium && !isHidden {
return chatTranslationState(context: context, peerId: peerId)
|> map { translationState -> ChatPresentationTranslationState? in

View File

@ -155,8 +155,11 @@ public func chatTranslationState(context: AccountContext, peerId: EnginePeer.Id)
var fromLangs: [String: Int] = [:]
var count = 0
for message in messages {
if let _ = URL(string: message.text) {
continue
}
if message.text.count > 10 {
let text = String(message.text.prefix(64))
let text = String(message.text.prefix(100))
languageRecognizer.processString(text)
let hypotheses = languageRecognizer.languageHypotheses(withMaximum: 3)
languageRecognizer.reset()