Skip to content

Commit

Permalink
Knock a room - added a char counter for the message (#3570)
Browse files Browse the repository at this point in the history
* added a char counter

* moved code
  • Loading branch information
Velin92 authored Dec 2, 2024
1 parent b808535 commit c7afde3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
14 changes: 11 additions & 3 deletions ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Compound
import SwiftUI

struct JoinRoomScreen: View {
private let maxKnockMessageLength = 500
@Environment(\.dynamicTypeSize) private var dynamicTypeSize

@ObservedObject var context: JoinRoomScreenViewModel.Context
Expand Down Expand Up @@ -103,14 +104,21 @@ struct JoinRoomScreen: View {
}
}
}

private var knockMessageFooterString: String {
guard !context.knockMessage.isEmpty else {
return L10n.screenJoinRoomKnockMessageDescription
}
return "\(context.knockMessage.count)/\(maxKnockMessageLength)"
}

@ViewBuilder
private var knockMessage: some View {
VStack(alignment: .leading, spacing: 12) {
HStack(spacing: 0) {
TextField("", text: $context.knockMessage, axis: .vertical)
.onChange(of: context.knockMessage) { _, newValue in
context.knockMessage = String(newValue.prefix(500))
context.knockMessage = String(newValue.prefix(maxKnockMessageLength))
}
.lineLimit(4, reservesSpace: true)
.font(.compound.bodyMD)
Expand All @@ -125,8 +133,8 @@ struct JoinRoomScreen: View {
.stroke(.compound.borderInteractivePrimary)
}

Text(L10n.screenJoinRoomKnockMessageDescription)
.font(.compound.bodyMD)
Text(knockMessageFooterString)
.font(.compound.bodySM)
.foregroundStyle(.compound.textSecondary)
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c7afde3

Please sign in to comment.