fix: bio editor not stable issue. resolve #265
This commit is contained in:
parent
7f617758c1
commit
d134178032
|
@ -195,33 +195,35 @@ extension ProfileHeaderViewController {
|
|||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
viewModel.isEditing
|
||||
.assign(to: \.isEditable, on: profileHeaderView.bioMetaText.textView)
|
||||
.store(in: &disposeBag)
|
||||
|
||||
viewModel.isEditing
|
||||
.removeDuplicates()
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] isEditing in
|
||||
guard let self = self else { return }
|
||||
guard isEditing else { return }
|
||||
// trigger once when toggle
|
||||
// and use delegate to update text style
|
||||
let initialNote = self.viewModel.editProfileInfo.note.value
|
||||
let metaContent = PlaintextMetaContent(string: initialNote ?? "")
|
||||
self.profileHeaderView.bioMetaText.configure(content: metaContent)
|
||||
let profileNote = Publishers.CombineLatest3(
|
||||
viewModel.isEditing.removeDuplicates(),
|
||||
viewModel.displayProfileInfo.note.removeDuplicates(),
|
||||
viewModel.editProfileInfoDidInitialized
|
||||
)
|
||||
.map { isEditing, displayNote, _ -> String? in
|
||||
if isEditing {
|
||||
return self.viewModel.editProfileInfo.note.value
|
||||
} else {
|
||||
return displayNote
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
|
||||
Publishers.CombineLatest3(
|
||||
viewModel.isEditing.removeDuplicates(),
|
||||
viewModel.displayProfileInfo.note.removeDuplicates(),
|
||||
profileNote.removeDuplicates(),
|
||||
viewModel.emojiMeta.removeDuplicates()
|
||||
)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] isEditing, note, emojiMeta in
|
||||
guard let self = self else { return }
|
||||
guard !isEditing else { return }
|
||||
|
||||
self.profileHeaderView.bioMetaText.textView.isEditable = isEditing
|
||||
|
||||
if isEditing {
|
||||
let metaContent = PlaintextMetaContent(string: note ?? "")
|
||||
self.profileHeaderView.bioMetaText.configure(content: metaContent)
|
||||
} else {
|
||||
let mastodonContent = MastodonContent(content: note ?? "", emojis: emojiMeta)
|
||||
do {
|
||||
let metaContent = try MastodonMetaContent.convert(document: mastodonContent)
|
||||
|
@ -231,7 +233,9 @@ extension ProfileHeaderViewController {
|
|||
self.profileHeaderView.bioMetaText.reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
profileHeaderView.bioMetaText.delegate = self
|
||||
|
||||
NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification, object: profileHeaderView.nameTextField)
|
||||
|
|
|
@ -31,6 +31,7 @@ final class ProfileHeaderViewModel {
|
|||
// output
|
||||
let displayProfileInfo = ProfileInfo()
|
||||
let editProfileInfo = ProfileInfo()
|
||||
let editProfileInfoDidInitialized = CurrentValueSubject<Void, Never>(Void()) // needs trigger initial event
|
||||
let isTitleViewDisplaying = CurrentValueSubject<Bool, Never>(false)
|
||||
var fieldDiffableDataSource: UICollectionViewDiffableDataSource<ProfileFieldSection, ProfileFieldItem>!
|
||||
|
||||
|
@ -52,6 +53,7 @@ final class ProfileHeaderViewModel {
|
|||
self.editProfileInfo.fields.value = account?.source?.fields?.compactMap { field in
|
||||
ProfileFieldItem.FieldValue(name: field.name, value: field.value)
|
||||
} ?? []
|
||||
self.editProfileInfoDidInitialized.send()
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
||||
|
|
Loading…
Reference in New Issue