Fix unretained story row cell in share button callback
This commit is contained in:
parent
aeecb19d2a
commit
4fb843a805
@ -1000,7 +1000,7 @@ extension StoryContextViewController: StoryItemMediaViewDelegate {
|
||||
for: item.message,
|
||||
in: self.context.thread(transaction: $0),
|
||||
attachment: attachment,
|
||||
sourceView: contextMenuButton,
|
||||
sourceView: { return contextMenuButton },
|
||||
transaction: $0
|
||||
))
|
||||
}
|
||||
|
||||
@ -178,10 +178,7 @@ extension MyStoriesViewController: UITableViewDelegate {
|
||||
|
||||
@available(iOS 13, *)
|
||||
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
||||
guard
|
||||
let item = item(for: indexPath),
|
||||
let cell = tableView.cellForRow(at: indexPath) as? SentStoryCell
|
||||
else {
|
||||
guard let item = item(for: indexPath) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -190,7 +187,10 @@ extension MyStoriesViewController: UITableViewDelegate {
|
||||
for: item.message,
|
||||
in: item.thread,
|
||||
attachment: item.attachment,
|
||||
sourceView: cell,
|
||||
sourceView: { [weak self] in
|
||||
// refetch the cell in case it changes out from underneath us.
|
||||
return self?.tableView(tableView, cellForRowAt: indexPath)
|
||||
},
|
||||
transaction: transaction
|
||||
)
|
||||
}
|
||||
@ -265,7 +265,6 @@ extension MyStoriesViewController: ContextMenuButtonDelegate {
|
||||
func contextMenuConfiguration(for contextMenuButton: DelegatingContextMenuButton) -> ContextMenuConfiguration? {
|
||||
guard
|
||||
let indexPath = (contextMenuButton as? IndexPathContextMenuButton)?.indexPath,
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: SentStoryCell.reuseIdentifier, for: indexPath) as? SentStoryCell,
|
||||
let item = self.item(for: indexPath)
|
||||
else {
|
||||
return nil
|
||||
@ -275,7 +274,10 @@ extension MyStoriesViewController: ContextMenuButtonDelegate {
|
||||
for: item.message,
|
||||
in: item.thread,
|
||||
attachment: item.attachment,
|
||||
sourceView: cell,
|
||||
sourceView: { [weak self] in
|
||||
// refetch the cell in case it changes out from underneath us.
|
||||
return self?.tableView.dequeueReusableCell(withIdentifier: SentStoryCell.reuseIdentifier, for: indexPath)
|
||||
},
|
||||
transaction: transaction
|
||||
)
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ class StoryContextMenuGenerator: Dependencies {
|
||||
|
||||
public func contextMenuActions(
|
||||
for model: StoryViewModel,
|
||||
sourceView: UIView
|
||||
sourceView: @escaping () -> UIView?
|
||||
) -> [ContextMenuAction] {
|
||||
return Self.databaseStorage.read {
|
||||
let thread = model.context.thread(transaction: $0)
|
||||
@ -78,7 +78,7 @@ class StoryContextMenuGenerator: Dependencies {
|
||||
for message: StoryMessage,
|
||||
in thread: TSThread?,
|
||||
attachment: StoryThumbnailView.Attachment,
|
||||
sourceView: UIView,
|
||||
sourceView: @escaping () -> UIView?,
|
||||
transaction: SDSAnyReadTransaction
|
||||
) -> [ContextMenuAction] {
|
||||
return [
|
||||
@ -95,7 +95,7 @@ class StoryContextMenuGenerator: Dependencies {
|
||||
@available(iOS 13, *)
|
||||
public func nativeContextMenuActions(
|
||||
for model: StoryViewModel,
|
||||
sourceView: UIView
|
||||
sourceView: @escaping () -> UIView?
|
||||
) -> [UIAction] {
|
||||
return Self.databaseStorage.read {
|
||||
let thread = model.context.thread(transaction: $0)
|
||||
@ -114,7 +114,7 @@ class StoryContextMenuGenerator: Dependencies {
|
||||
for message: StoryMessage,
|
||||
in thread: TSThread?,
|
||||
attachment: StoryThumbnailView.Attachment,
|
||||
sourceView: UIView,
|
||||
sourceView: @escaping () -> UIView?,
|
||||
transaction: SDSAnyReadTransaction
|
||||
) -> [UIAction] {
|
||||
return [
|
||||
@ -690,7 +690,7 @@ extension StoryContextMenuGenerator {
|
||||
private func shareAction(
|
||||
message: StoryMessage,
|
||||
attachment: StoryThumbnailView.Attachment,
|
||||
sourceView: UIView
|
||||
sourceView: @escaping () -> UIView?
|
||||
) -> GenericContextAction? {
|
||||
guard message.authorAddress.isLocalAddress else {
|
||||
// Can only share one's own stories.
|
||||
@ -702,8 +702,8 @@ extension StoryContextMenuGenerator {
|
||||
comment: "Context menu action to share the selected story"
|
||||
),
|
||||
icon: .messageActionShare20,
|
||||
handler: { [weak sourceView, weak self] completion in
|
||||
guard let sourceView = sourceView else {
|
||||
handler: { [weak self] completion in
|
||||
guard let sourceView = sourceView() else {
|
||||
completion(false)
|
||||
return
|
||||
}
|
||||
|
||||
@ -406,17 +406,16 @@ extension StoriesViewController: UITableViewDelegate {
|
||||
|
||||
@available(iOS 13, *)
|
||||
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
||||
guard
|
||||
let model = model(for: indexPath),
|
||||
let cell = tableView.cellForRow(at: indexPath)
|
||||
else {
|
||||
guard let model = model(for: indexPath) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return .init(identifier: indexPath as NSCopying, previewProvider: nil, actionProvider: { [weak self] _ in
|
||||
let actions = self?.contextMenuGenerator.nativeContextMenuActions(
|
||||
for: model,
|
||||
sourceView: cell
|
||||
sourceView: { [weak self] in
|
||||
return self?.tableView.cellForRow(at: indexPath)
|
||||
}
|
||||
) ?? []
|
||||
return .init(children: actions)
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user