Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS-2478 Editor | fix some animations #1095

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ final class TextBlockContentView: UIView, BlockContentView, DynamicHeightView, F

focusSubscription = configuration
.focusPublisher
.receiveOnMain()
.sink { [weak self] focus in
DispatchQueue.main.async {
self?.textView.textView.setFocus(focus)
}

}
self?.textView.textView.setFocus(focus)
}

resetSubscription = configuration.resetPublisher.sink { [weak self] configuration in
configuration.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ final class EditorPageController: UIViewController {
private let syncStatusData: SyncStatusData

private var cancellables = [AnyCancellable]()
private var applyAnimationConfig = false
private var dataSourceAnimationEnabled: Bool {
applyAnimationConfig ? EditorPageConfigurationConstants.dataSourceAnimationEnabled : false
}

// MARK: - Initializers
init(
Expand Down Expand Up @@ -320,24 +324,14 @@ extension EditorPageController: EditorPageViewInput {

func textBlockWillBeginEditing() { }

func reload(items: [EditorItem]) {
guard items.count > 0 else { return }

var snapshot = dataSource.snapshot()

let existingItems = items.filter { snapshot.itemIdentifiers.contains($0) }
snapshot.reloadItems(existingItems)
dataSource.apply(snapshot, animatingDifferences: true)
}

func visibleRect(to view: UIView) -> CGRect {
return collectionView.convert(collectionView.bounds, to: view)
}

func update(header: ObjectHeader) {
var headerSnapshot = NSDiffableDataSourceSectionSnapshot<EditorItem>()
headerSnapshot.append([.header(header)])
dataSource.apply(headerSnapshot, to: .header, animatingDifferences: EditorPageConfigurationConstants.dataSourceAnimationEnabled)
dataSource.apply(headerSnapshot, to: .header, animatingDifferences: false)

navigationBarHelper.configureNavigationBar(using: header)
}
Expand Down Expand Up @@ -368,22 +362,24 @@ extension EditorPageController: EditorPageViewInput {

let existingItems = items.filter { snapshot.itemIdentifiers.contains($0) }
snapshot.reconfigureItems(existingItems)
dataSource.apply(snapshot, animatingDifferences: true)
dataSource.apply(snapshot, animatingDifferences: true)
}

func update(
changes: CollectionDifference<EditorItem>?,
allModels: [EditorItem],
isRealData: Bool,
completion: @escaping () -> Void
) {
var blocksSnapshot = NSDiffableDataSourceSectionSnapshot<EditorItem>()
blocksSnapshot.append(allModels)

applyBlocksSectionSnapshot(
blocksSnapshot,
animatingDifferences: EditorPageConfigurationConstants.dataSourceAnimationEnabled,
animatingDifferences: dataSourceAnimationEnabled,
completion: completion
)
applyAnimationConfig = isRealData
}

func scrollToTopBlock(blockId: String) {
Expand Down Expand Up @@ -650,7 +646,7 @@ private extension EditorPageController {
dataSource.apply(
snapshot,
to: .main,
animatingDifferences: EditorPageConfigurationConstants.dataSourceAnimationEnabled,
animatingDifferences: animatingDifferences,
completion: completion
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Services
import UIKit

protocol EditorCollectionReloadable: AnyObject {
func reload(items: [EditorItem])
func reconfigure(items: [EditorItem])
func itemDidChangeFrame(item: EditorItem)
func scrollToTopBlock(blockId: String) // Change to editorItem
Expand All @@ -23,6 +22,7 @@ protocol EditorPageViewInput: EditorCollectionReloadable {
func update(
changes: CollectionDifference<EditorItem>?,
allModels: [EditorItem],
isRealData: Bool,
completion: @escaping () -> Void
)
func update(syncStatus: SyncStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ final class EditorPageViewModel: EditorPageViewModelProtocol, EditorBottomNaviga
viewInput?.update(
changes: nil,
allModels: [shimmeringBlockViewModel],
isRealData: false,
completion: { }
)
}
Expand All @@ -135,7 +136,7 @@ final class EditorPageViewModel: EditorPageViewModelProtocol, EditorBottomNaviga

guard document.isOpened else { return }

viewInput?.update(changes: difference, allModels: modelsHolder.items) { [weak self] in
viewInput?.update(changes: difference, allModels: modelsHolder.items, isRealData: true) { [weak self] in
guard let self else { return }
cursorManager.handleGeneralUpdate(with: modelsHolder.items, type: document.details?.type)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ final class EditorBlockCollectionController: EditorCollectionReloadable {
self.viewInput = viewInput
}

func reload(items: [EditorItem]) {
viewInput?.reload(items: items)
}

func reconfigure(items: [EditorItem]) {
viewInput?.reconfigure(items: items)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AnytypeCore
import UIKit
import ProtobufMessages

@MainActor
protocol KeyboardActionHandlerProtocol {
func handle(
info: BlockInformation,
Expand All @@ -12,6 +13,7 @@ protocol KeyboardActionHandlerProtocol {
) async throws
}

@MainActor
final class KeyboardActionHandler: KeyboardActionHandlerProtocol {
private let documentId: String
private let service: BlockActionServiceProtocol
Expand All @@ -21,7 +23,7 @@ final class KeyboardActionHandler: KeyboardActionHandlerProtocol {
private weak var modelsHolder: EditorMainItemModelsHolder?
private let editorCollectionController: EditorBlockCollectionController

init(
nonisolated init(
documentId: String,
service: BlockActionServiceProtocol,
blockService: BlockServiceProtocol,
Expand Down Expand Up @@ -110,7 +112,6 @@ final class KeyboardActionHandler: KeyboardActionHandlerProtocol {
}
}

@MainActor
private func onDelete(text: BlockText, info: BlockInformation, parent: BlockInformation, textView: UITextView) async throws {
if text.contentType.isList || text.contentType == .quote || text.contentType == .callout {
try await service.turnInto(.text, blockId: info.id)
Expand Down
Loading