Story location picking

This commit is contained in:
Ilya Laktyushin
2023-07-30 15:01:25 +02:00
parent b3146436dc
commit b70586eb28
43 changed files with 2397 additions and 133 deletions

View File

@@ -76,6 +76,12 @@ public final class TextFieldComponent: Component {
}
}
public enum FormatMenuAvailability: Equatable {
case available
case locked
case none
}
public let context: AccountContext
public let strings: PresentationStrings
public let externalState: ExternalState
@@ -83,6 +89,8 @@ public final class TextFieldComponent: Component {
public let textColor: UIColor
public let insets: UIEdgeInsets
public let hideKeyboard: Bool
public let formatMenuAvailability: FormatMenuAvailability
public let lockedFormatAction: () -> Void
public let present: (ViewController) -> Void
public let paste: (PasteData) -> Void
@@ -94,6 +102,8 @@ public final class TextFieldComponent: Component {
textColor: UIColor,
insets: UIEdgeInsets,
hideKeyboard: Bool,
formatMenuAvailability: FormatMenuAvailability,
lockedFormatAction: @escaping () -> Void,
present: @escaping (ViewController) -> Void,
paste: @escaping (PasteData) -> Void
) {
@@ -104,6 +114,8 @@ public final class TextFieldComponent: Component {
self.textColor = textColor
self.insets = insets
self.hideKeyboard = hideKeyboard
self.formatMenuAvailability = formatMenuAvailability
self.lockedFormatAction = lockedFormatAction
self.present = present
self.paste = paste
}
@@ -127,6 +139,9 @@ public final class TextFieldComponent: Component {
if lhs.hideKeyboard != rhs.hideKeyboard {
return false
}
if lhs.formatMenuAvailability != rhs.formatMenuAvailability {
return false
}
return true
}
@@ -387,6 +402,22 @@ public final class TextFieldComponent: Component {
return UIMenu(children: suggestedActions)
}
let strings = component.strings
if case .none = component.formatMenuAvailability {
return UIMenu(children: suggestedActions)
}
if case .locked = component.formatMenuAvailability {
var updatedActions = suggestedActions
let formatAction = UIAction(title: strings.TextFormat_Format, image: nil) { [weak self] action in
if let self {
self.component?.lockedFormatAction()
}
}
updatedActions.insert(formatAction, at: 1)
return UIMenu(children: updatedActions)
}
var actions: [UIAction] = [
UIAction(title: strings.TextFormat_Bold, image: nil) { [weak self] action in
if let self {