Skip to content

Commit

Permalink
PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Oct 20, 2023
1 parent 40c5116 commit da687ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
4 changes: 4 additions & 0 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
000765812BABB81F5174C601 /* AppLockSetupPINScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEDC38E389B89BCF5C1AFD4A /* AppLockSetupPINScreenUITests.swift */; };
0033481EE363E4914295F188 /* LocalizationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C070FD43DC6BF4E50217965A /* LocalizationTests.swift */; };
0180C44B997EDA8D21F883AC /* RoomNotificationSettingsCustomSectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B746EFA112532A7B701FB914 /* RoomNotificationSettingsCustomSectionView.swift */; };
0206016CCEF6EF9365916768 /* AppLockSettingsScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33284693F54382F46CFD2EDD /* AppLockSettingsScreenViewModelProtocol.swift */; };
Expand Down Expand Up @@ -1577,6 +1578,7 @@
AE40D4A5DD857AC16EED945A /* URLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSession.swift; sourceTree = "<group>"; };
AE52983FAFB4E0998C00EE8A /* CancellableTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancellableTask.swift; sourceTree = "<group>"; };
AE5DDBEBBA17973ED4638823 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = de; path = de.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
AEDC38E389B89BCF5C1AFD4A /* AppLockSetupPINScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLockSetupPINScreenUITests.swift; sourceTree = "<group>"; };
AEEAFB646E583655652C3D04 /* RoomStateEventStringBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomStateEventStringBuilderTests.swift; sourceTree = "<group>"; };
AF042B0FB2EE88977C91E330 /* portrait_test_image.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = portrait_test_image.jpg; sourceTree = "<group>"; };
AF11DD57D9FACF2A757AB024 /* AnalyticsPromptUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsPromptUITests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3565,6 +3567,7 @@
7D0CBC76C80E04345E11F2DB /* Application.swift */,
349C633291427A0F29C28C54 /* AppLockScreenUITests.swift */,
5F088B61525099A48909743B /* AppLockSettingsScreenUITests.swift */,
AEDC38E389B89BCF5C1AFD4A /* AppLockSetupPINScreenUITests.swift */,
5D2D0A6F1ABC99D29462FB84 /* AuthenticationCoordinatorUITests.swift */,
C6FEA87EA3752203065ECE27 /* BugReportUITests.swift */,
1D8866FE1CCCF10305FCACBC /* CallScreenUITests.swift */,
Expand Down Expand Up @@ -5755,6 +5758,7 @@
BF675964C9159F718589C36A /* AnalyticsSettingsScreenUITests.swift in Sources */,
F05516474DB42369FD976CEF /* AppLockScreenUITests.swift in Sources */,
61C345258DD392477E79A3B5 /* AppLockSettingsScreenUITests.swift in Sources */,
000765812BABB81F5174C601 /* AppLockSetupPINScreenUITests.swift in Sources */,
7405B4824D45BA7C3D943E76 /* Application.swift in Sources */,
ACF094CF3BF02DBFA6DFDE60 /* AuthenticationCoordinatorUITests.swift in Sources */,
7756C4E90CABE6F14F7920A0 /* BugReportUITests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ struct PINTextField: View {
.textFieldStyle(PINTextFieldStyle(pinCode: pinCode, isSecure: isSecure))
.keyboardType(.numberPad)
.onChange(of: pinCode) { newValue in
// add some tests.
let sanitized = sanitize(newValue)
if sanitized != newValue { pinCode = sanitized }
if sanitized != newValue {
MXLog.warning("PIN code input sanitized.")
pinCode = sanitized
}
}
}

Expand Down Expand Up @@ -59,7 +61,7 @@ private struct PINTextFieldStyle: TextFieldStyle {
public func _body(configuration: TextField<_Label>) -> some View {
HStack(spacing: 8) {
ForEach(0..<4) { index in
PINTextFieldDigit(pinCode: pinCode, index: index, isSecure: isSecure)
PINDigitField(digit: digit(index))
}
}
.overlay {
Expand All @@ -69,31 +71,30 @@ private struct PINTextFieldStyle: TextFieldStyle {
}
.onTapGesture { isFocussed = true }
}

func digit(_ index: Int) -> Character? {
guard pinCode.count > index else { return nil }
let stringIndex = pinCode.index(pinCode.startIndex, offsetBy: index)
return isSecure ? "" : pinCode[stringIndex]
}
}

/// A single digit shown within the text field style.
private struct PINTextFieldDigit: View {
let pinCode: String
let index: Int
let isSecure: Bool

var isEntered: Bool { pinCode.count > index }

var stringIndex: String.Index { pinCode.index(pinCode.startIndex, offsetBy: index) }
var character: Character { isSecure ? "" : pinCode[stringIndex] }
var digit: String { isEntered ? String(character) : "" }
private struct PINDigitField: View {
let digit: Character?

var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(Color.compound.bgSubtlePrimary)
.opacity(isEntered ? 1 : 0)
RoundedRectangle(cornerRadius: 8, style: .continuous)
.inset(by: 0.5)
.stroke(Color.compound.iconPrimary, lineWidth: 1)
.opacity(isEntered ? 0 : 1)
Text(digit)
.font(.compound.headingMDBold)
if let digit {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(Color.compound.bgSubtlePrimary)
Text(String(digit))
.font(.compound.headingMDBold)
} else {
RoundedRectangle(cornerRadius: 8, style: .continuous)
.inset(by: 0.5)
.stroke(Color.compound.iconPrimary, lineWidth: 1)
}
}
.frame(width: 48, height: 48)
}
Expand Down

0 comments on commit da687ef

Please sign in to comment.