mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Periphery cleanup (#5893)
This commit is contained in:
+1
-1
@@ -72,7 +72,7 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
// MARK: - Private
|
||||
|
||||
private func updateRoomInfo(_ roomInfo: RoomInfoProxyProtocol) {
|
||||
if let powerLevels = roomProxy.infoPublisher.value.powerLevels {
|
||||
if let powerLevels = roomInfo.powerLevels {
|
||||
canMentionAllUsers = powerLevels.canOwnUserTriggerRoomNotification()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +75,6 @@ struct ComposerToolbarViewState: BindableState {
|
||||
/// Could be false if sending is disabled in the room
|
||||
var canSend = true
|
||||
var suggestions: [SuggestionItem] = []
|
||||
var audioPlayerState: AudioPlayerState
|
||||
var audioRecorderState: AudioRecorderState
|
||||
|
||||
var isRoomEncrypted: Bool
|
||||
var isLocationSharingEnabled: Bool
|
||||
|
||||
@@ -35,7 +35,6 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
||||
}
|
||||
|
||||
private struct WysiwygLinkData {
|
||||
let action: LinkAction
|
||||
let range: NSRange
|
||||
var url: String
|
||||
var text: String
|
||||
@@ -65,8 +64,6 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
||||
attributedStringBuilder = AttributedStringBuilder(cacheKey: "Composer", mentionBuilder: mentionBuilder)
|
||||
|
||||
super.init(initialViewState: ComposerToolbarViewState(wysiwygViewModel: wysiwygViewModel,
|
||||
audioPlayerState: .init(id: .recorderPreview, title: L10n.commonVoiceMessage, duration: 0),
|
||||
audioRecorderState: .init(),
|
||||
isRoomEncrypted: roomProxy.infoPublisher.value.isEncrypted,
|
||||
isLocationSharingEnabled: appSettings.mapTilerSettings.publisher.value.isEnabled,
|
||||
bindings: .init()),
|
||||
@@ -580,10 +577,8 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
||||
switch mode {
|
||||
case .default:
|
||||
break
|
||||
case .recordVoiceMessage(let audioRecorderState):
|
||||
state.audioRecorderState = audioRecorderState
|
||||
case .previewVoiceMessage(let audioPlayerState, _, _):
|
||||
state.audioPlayerState = audioPlayerState
|
||||
case .recordVoiceMessage, .previewVoiceMessage:
|
||||
break
|
||||
case .edit, .reply:
|
||||
// Focus composer when switching to reply/edit
|
||||
state.bindings.composerFocused = true
|
||||
@@ -645,8 +640,7 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
||||
|
||||
private func createLinkAlert() {
|
||||
let linkAction = wysiwygViewModel.getLinkAction()
|
||||
currentLinkData = WysiwygLinkData(action: linkAction,
|
||||
range: wysiwygViewModel.attributedContent.selection,
|
||||
currentLinkData = WysiwygLinkData(range: wysiwygViewModel.attributedContent.selection,
|
||||
url: linkAction.url ?? "",
|
||||
text: "")
|
||||
|
||||
|
||||
-1
@@ -9,7 +9,6 @@
|
||||
import Combine
|
||||
import WysiwygComposer
|
||||
|
||||
// periphery: ignore - markdown protocol
|
||||
protocol ComposerToolbarViewModelProtocol {
|
||||
var actions: AnyPublisher<ComposerToolbarViewModelAction, Never> { get }
|
||||
var context: ComposerToolbarViewModelType.Context { get }
|
||||
|
||||
@@ -33,7 +33,6 @@ struct MessageComposer: View {
|
||||
let onAppearAction: () -> Void
|
||||
|
||||
@State private var composerTranslation: CGFloat = 0
|
||||
private let composerShape = RoundedRectangle(cornerRadius: 21, style: .circular)
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
|
||||
+2
-15
@@ -151,7 +151,6 @@ private struct UITextViewWrapper: UIViewRepresentable {
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(text: $text,
|
||||
selectedRange: $selectedRange,
|
||||
maxHeight: maxHeight,
|
||||
keyHandler: keyHandler,
|
||||
pasteHandler: pasteHandler)
|
||||
}
|
||||
@@ -160,19 +159,15 @@ private struct UITextViewWrapper: UIViewRepresentable {
|
||||
private var text: Binding<NSAttributedString>
|
||||
private var selectedRange: Binding<NSRange>
|
||||
|
||||
private let maxHeight: CGFloat
|
||||
|
||||
private let keyHandler: GenericKeyHandler
|
||||
private let pasteHandler: PasteHandler
|
||||
|
||||
init(text: Binding<NSAttributedString>,
|
||||
selectedRange: Binding<NSRange>,
|
||||
maxHeight: CGFloat,
|
||||
keyHandler: @escaping GenericKeyHandler,
|
||||
pasteHandler: @escaping PasteHandler) {
|
||||
self.text = text
|
||||
self.selectedRange = selectedRange
|
||||
self.maxHeight = maxHeight
|
||||
self.keyHandler = keyHandler
|
||||
self.pasteHandler = pasteHandler
|
||||
}
|
||||
@@ -211,7 +206,6 @@ private protocol ElementTextViewDelegate: AnyObject {
|
||||
|
||||
private class ElementTextView: UITextView, PillAttachmentViewProviderDelegate {
|
||||
private(set) var timelineContext: TimelineViewModel.Context?
|
||||
private var presendCallback: Binding<(() -> Void)?>
|
||||
private var pillViews = NSHashTable<UIView>.weakObjects()
|
||||
|
||||
weak var elementDelegate: ElementTextViewDelegate?
|
||||
@@ -219,7 +213,6 @@ private class ElementTextView: UITextView, PillAttachmentViewProviderDelegate {
|
||||
init(timelineContext: TimelineViewModel.Context?,
|
||||
presendCallback: Binding<(() -> Void)?>) {
|
||||
self.timelineContext = timelineContext
|
||||
self.presendCallback = presendCallback
|
||||
|
||||
super.init(frame: .zero, textContainer: nil)
|
||||
|
||||
@@ -241,10 +234,12 @@ private class ElementTextView: UITextView, PillAttachmentViewProviderDelegate {
|
||||
UIKeyCommand(input: "\r", modifierFlags: [], action: #selector(enterKeyPressed))]
|
||||
}
|
||||
|
||||
// periphery:ignore:parameters sender - required for objc selector
|
||||
@objc func shiftEnterKeyPressed(sender: UIKeyCommand) {
|
||||
elementDelegate?.textViewDidReceiveShiftEnterKeyPress(self)
|
||||
}
|
||||
|
||||
// periphery:ignore:parameters sender - required for objc selector
|
||||
@objc func enterKeyPressed(sender: UIKeyCommand) {
|
||||
elementDelegate?.textViewDidReceiveKeyPress(self, key: .keyboardReturnOrEnter)
|
||||
}
|
||||
@@ -318,14 +313,6 @@ private class ElementTextView: UITextView, PillAttachmentViewProviderDelegate {
|
||||
pillViews.add(pillView)
|
||||
}
|
||||
|
||||
func flushPills() {
|
||||
for view in pillViews.allObjects {
|
||||
view.alpha = 0.0
|
||||
view.removeFromSuperview()
|
||||
}
|
||||
pillViews.removeAllObjects()
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func acceptCurrentSuggestion() {
|
||||
|
||||
@@ -98,55 +98,6 @@ struct SwipeRightAction<Label: View>: ViewModifier {
|
||||
})
|
||||
}
|
||||
|
||||
private var oldGesture: some Gesture {
|
||||
DragGesture()
|
||||
.updating($dragGestureActive) { _, state, _ in
|
||||
// Available actions should be computed on the fly so we use a gesture state change
|
||||
// to ask whether the move should be started or not.
|
||||
state = true
|
||||
}
|
||||
.onChanged { value in
|
||||
guard canStartAction, value.translation.width > value.translation.height else {
|
||||
return
|
||||
}
|
||||
|
||||
// Due to https://forums.developer.apple.com/forums/thread/760035 we had to make
|
||||
// the drag a simultaneous gesture otherwise it was impossible to scroll the timeline.
|
||||
// Therefore we need to prevent the animation to run if the user is to scrolling vertically.
|
||||
// It would be nice if we could somehow abort the gesture in this case.
|
||||
let width: CGFloat = if value.translation.width > abs(value.translation.height) {
|
||||
value.translation.width
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
|
||||
// We want to add a spring like behaviour to the drag in which the view
|
||||
// moves slower the more it's dragged. We use a circular easing function
|
||||
// to generate those values up to the `swipeThreshold`
|
||||
// The final translation will be between 0 and `swipeThreshold` with the action being enabled from
|
||||
// `actionThreshold` onwards
|
||||
let screenWidthNormalisedTranslation = max(0.0, min(width, swipeThreshold)) / swipeThreshold
|
||||
let easedTranslation = circularEaseOut(screenWidthNormalisedTranslation)
|
||||
xOffset = easedTranslation * xOffsetThreshold
|
||||
|
||||
if xOffset > actionThreshold {
|
||||
if !hasReachedActionThreshold {
|
||||
feedbackGenerator.impactOccurred()
|
||||
hasReachedActionThreshold = true
|
||||
}
|
||||
} else {
|
||||
hasReachedActionThreshold = false
|
||||
}
|
||||
}
|
||||
.onEnded { _ in
|
||||
if xOffset > actionThreshold {
|
||||
action()
|
||||
}
|
||||
|
||||
xOffset = 0.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Used to compute the horizontal translation amount.
|
||||
/// The more it's dragged the less it moves on a circular ease out curve
|
||||
private func circularEaseOut(_ value: Double) -> Double {
|
||||
|
||||
Reference in New Issue
Block a user