Skip to content

Conversation

leoxiao-sap
Copy link
Collaborator

@leoxiao-sap leoxiao-sap commented Aug 26, 2025

Dev result
Simulator Screenshot - iPhone 16e - 2025-10-17 at 10 40 35
Uploading Simulator Screenshot - iPhone 16e - 2025-10-17 at 10.40.17.png…

Simulator Screenshot - iPhone 16 - 2025-08-25 at 18 14 29
Simulator.Screen.Recording.-.iPhone.16.-.2025-08-25.at.18.14.04.mp4

@leoxiao-sap leoxiao-sap requested a review from a team as a code owner August 26, 2025 08:14
@leoxiao-sap leoxiao-sap requested review from billzhou0223 and removed request for a team August 26, 2025 08:14
@dyongxu dyongxu requested a review from janhuachu August 27, 2025 16:40
Copy link
Contributor

@janhuachu janhuachu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to also move the FUIFormattedStringEditing protocol and its implementations FUINumberFormatter and FUIPhoneNumberFormatter to SwiftUI side as FormattedStringEditing, NumberFormatter, and PhoneNumberFormatter.

The GenericTextFormatter should also implement FormattedStringEditing.

Then in UIKit side use the SwiftUI implementation using the alias to link the old class name to new class name.

@KevinZK
Copy link
Collaborator

KevinZK commented Aug 28, 2025

Issue: #1162

Should compatibility with the system API Formatter and FormatStyle be considered?
TextField(<#T##LocalizedStringKey#>, value: <#T##Binding<V>#>, formatter: <#T##Formatter#>)
TextField(<#T##LocalizedStringKey#>, value: <#T##Binding<F.FormatInput?>#>, format: <#T##F#>)

@leoxiao-sap
Copy link
Collaborator Author

leoxiao-sap commented Aug 28, 2025

I think we need to also move the FUIFormattedStringEditing protocol and its implementations FUINumberFormatter and FUIPhoneNumberFormatter to SwiftUI side as FormattedStringEditing, NumberFormatter, and PhoneNumberFormatter.

The GenericTextFormatter should also implement FormattedStringEditing.

Then in UIKit side use the SwiftUI implementation using the alias to link the old class name to new class name.

I added the related files, thank you!

// sourcery: defaultValue = false
var isSecureEnabled: Bool? { get set }
// sourcery: default.value = nil
var formatter: GenericTextFormatter? { get set }
Copy link
Contributor

@janhuachu janhuachu Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use FormattedStringEditing as the formatter type to allow PhoneNumberFormatter and CustomNumberFormatter.

Copy link
Collaborator Author

@leoxiao-sap leoxiao-sap Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @janhuachu,
Based on the initial discussion with David, we believed that the Generic Text Formatter could cover the functionalities of both PhoneNumberFormatter and CustomNumberFormatter, which is why I didn’t migrate PhoneNumberFormatter and CustomNumberFormatter initially. Now, it appears that these are needed for UIKit compatibility, so I’ve renamed and added them directly. Please correct me if my understanding is inaccurate.

To support PhoneNumberFormatter and CustomNumberFormatter in SwiftUI, implementation adjustments are required because SwiftUI’s TextField doesn’t natively support cursor manipulation. Currently, in SwiftUI, the Generic Text Formatter deletes characters from the middle by jumping to the end and deleting backward. If cursor positioning behavior (like in UIKit) is needed, additional extensions would be necessary, as both PhoneNumberFormatter and CustomNumberFormatter involve cursor operations during deletion.

Moreover, the timing of inserting spaces, hyphens, and other formatting characters differs between PhoneNumberFormatter/CustomNumberFormatter and the Generic Text Formatter.

I have fixed all "Force Unwrapping Violation" warning.
Thank you
cc: @dyongxu

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leoxiao-sap I think it does not make sense if you just move FUINumberFormatter and FUIPhoneNumberFormatter to SwiftUI part without changing the formatter type to optional GenericTextFormatter.
I think it is better to make the formatter type to FormattedStringEdting and move the 2 formatters to the SwiftUI side.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janhuachu
Thank you for your answer, I will do this update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leoxiao-sap I think it does not make sense if you just move FUINumberFormatter and FUIPhoneNumberFormatter to SwiftUI part without changing the formatter type to optional GenericTextFormatter. I think it is better to make the formatter type to FormattedStringEdting and move the 2 formatters to the SwiftUI side.

@janhuachu I have completed this update. Could you please review it? Thank you!

}

let prefix = (isPositive ? self.positivePrefix : self.negativePrefix)!
let suffix = (isPositive ? self.positiveSuffix : self.negativeSuffix)!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix all the "Force Unwrapping Violation" warnings.

Copy link
Contributor

@janhuachu janhuachu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, good implementation. Please change the formatter's type to FormattedStringEditing to allow developer use CustomNumberFormatter and PhoneNumberFormatter. Also, address the "Force Unwrapping Violation" warnings.

}

func hasExactly(_ count: Int, consecutive character: Character) -> Bool {
guard count > 0 else { return false }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty Count Violation: Prefer checking isEmpty over comparing count to zero. (empty_count)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants