Skip to content

Commit bddfbac

Browse files
committed
Tune down version availability
1 parent 3e84016 commit bddfbac

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

InputMask.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "InputMask"
3-
spec.version = "7.2.0"
3+
spec.version = "7.2.1"
44
spec.summary = "InputMask"
55
spec.description = "User input masking library."
66
spec.homepage = "https://github.com/RedMadRobot/input-mask-ios"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<img src="Documentation/Assets/logo.png" alt="Input Mask" height="102" />
22

3-
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRedMadRobot%2Finput-mask-ios%2Fbadge%3Ftype%3Dswift-versions&style=for-the-badge)](https://swiftpackageindex.com/RedMadRobot/input-mask-ios) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRedMadRobot%2Finput-mask-ios%2Fbadge%3Ftype%3Dplatforms&style=for-the-badge)](https://swiftpackageindex.com/RedMadRobot/input-mask-ios) [![Pod Version Badge](https://img.shields.io/badge/POD-v7.2.0-blue?logo=cocoapods&style=for-the-badge)](https://cocoapods.org/pods/InputMask) [![Awesome](https://img.shields.io/badge/-mentioned_in_awesome_iOS-CCA6C4.svg?colorA=CCA6C4&colorB=261120&logoWidth=20&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMTAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI%2BICAgIDxwYXRoIGZpbGw9IiMyNjExMjAiIGQ9Ik0xOS4xNCA0LjVMMTQuMjMgMGwtLjY5Ljc1IDQuMDkgMy43NUgxLjUxTDUuNi43NSA0LjkxIDAgMCA0LjV2Mi45N0MwIDguODEgMS4yOSA5LjkgMi44OCA5LjloMy4wM2MxLjU5IDAgMi44OC0xLjA5IDIuODgtMi40M1Y1LjUyaDEuNTd2MS45NWMwIDEuMzQgMS4yOSAyLjQzIDIuODggMi40M2gzLjAzYzEuNTkgMCAyLjg4LTEuMDkgMi44OC0yLjQzbC0uMDEtMi45N3oiLz48L3N2Zz4%3D&style=for-the-badge)](https://github.com/vsouza/awesome-ios) [![Actions](https://img.shields.io/github/actions/workflow/status/RedMadRobot/input-mask-ios/swift.yml?style=for-the-badge)](https://github.com/RedMadRobot/input-mask-ios/actions/workflows/swift.yml) [![Android](https://img.shields.io/badge/-android_version-red?color=teal&logo=android&style=for-the-badge)](https://github.com/RedMadRobot/input-mask-android) [![Telegram](https://img.shields.io/badge/-telegram_author-red?color=blue&logo=telegram&style=for-the-badge)](https://t.me/jeorge_taflanidi) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge)](#license)
3+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRedMadRobot%2Finput-mask-ios%2Fbadge%3Ftype%3Dswift-versions&style=for-the-badge)](https://swiftpackageindex.com/RedMadRobot/input-mask-ios) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRedMadRobot%2Finput-mask-ios%2Fbadge%3Ftype%3Dplatforms&style=for-the-badge)](https://swiftpackageindex.com/RedMadRobot/input-mask-ios) [![Pod Version Badge](https://img.shields.io/badge/POD-v7.2.1-blue?logo=cocoapods&style=for-the-badge)](https://cocoapods.org/pods/InputMask) [![Awesome](https://img.shields.io/badge/-mentioned_in_awesome_iOS-CCA6C4.svg?colorA=CCA6C4&colorB=261120&logoWidth=20&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMTAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI%2BICAgIDxwYXRoIGZpbGw9IiMyNjExMjAiIGQ9Ik0xOS4xNCA0LjVMMTQuMjMgMGwtLjY5Ljc1IDQuMDkgMy43NUgxLjUxTDUuNi43NSA0LjkxIDAgMCA0LjV2Mi45N0MwIDguODEgMS4yOSA5LjkgMi44OCA5LjloMy4wM2MxLjU5IDAgMi44OC0xLjA5IDIuODgtMi40M1Y1LjUyaDEuNTd2MS45NWMwIDEuMzQgMS4yOSAyLjQzIDIuODggMi40M2gzLjAzYzEuNTkgMCAyLjg4LTEuMDkgMi44OC0yLjQzbC0uMDEtMi45N3oiLz48L3N2Zz4%3D&style=for-the-badge)](https://github.com/vsouza/awesome-ios) [![Actions](https://img.shields.io/github/actions/workflow/status/RedMadRobot/input-mask-ios/swift.yml?style=for-the-badge)](https://github.com/RedMadRobot/input-mask-ios/actions/workflows/swift.yml) [![Android](https://img.shields.io/badge/-android_version-red?color=teal&logo=android&style=for-the-badge)](https://github.com/RedMadRobot/input-mask-android) [![Telegram](https://img.shields.io/badge/-telegram_author-red?color=blue&logo=telegram&style=for-the-badge)](https://t.me/jeorge_taflanidi) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge)](#license)
44

55
Input masks restrict data input and allow you to guide users to enter correct values.
66
Check out our [wiki](https://github.com/RedMadRobot/input-mask-ios/wiki) for quick start and further reading.

Source/InputMask/InputMask/Classes/View/NumberInputListener.swift

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import UIKit
2424

2525
- seealso: the ``NumberInputListener/formatter`` field
2626
*/
27-
@available(iOS 16.0, tvOS 16.0, *)
2827
open class NumberInputListener: MaskedTextInputListener {
2928
private static let decimalSeparator = "."
3029

@@ -141,11 +140,23 @@ open class NumberInputListener: MaskedTextInputListener {
141140

142141
let numberOfOccurrencesOfDecimalSeparator = digitsAndDecimalSeparators.numberOfOccurrencesOf(NumberInputListener.decimalSeparator)
143142
if numberOfOccurrencesOfDecimalSeparator > 1 {
144-
digitsAndDecimalSeparators =
145-
digitsAndDecimalSeparators
146-
.reversed
147-
.replacing(NumberInputListener.decimalSeparator, with: "", maxReplacements: numberOfOccurrencesOfDecimalSeparator - 1)
148-
.reversed
143+
if #available(iOS 16.0, *) {
144+
digitsAndDecimalSeparators =
145+
digitsAndDecimalSeparators
146+
.reversed
147+
.replacing(NumberInputListener.decimalSeparator, with: "", maxReplacements: numberOfOccurrencesOfDecimalSeparator - 1)
148+
.reversed
149+
} else {
150+
// TODO: remove
151+
digitsAndDecimalSeparators = digitsAndDecimalSeparators.reversed
152+
digitsAndDecimalSeparators = replace(
153+
NumberInputListener.decimalSeparator,
154+
in: digitsAndDecimalSeparators,
155+
with: "",
156+
maxReplacements: numberOfOccurrencesOfDecimalSeparator - 1
157+
)
158+
digitsAndDecimalSeparators = digitsAndDecimalSeparators.reversed
159+
}
149160
}
150161

151162
let components = digitsAndDecimalSeparators.components(separatedBy: NumberInputListener.decimalSeparator)
@@ -183,6 +194,28 @@ open class NumberInputListener: MaskedTextInputListener {
183194
]
184195
return character
185196
}
197+
198+
private func replace(
199+
_ substring: String,
200+
in origin: String,
201+
with replacementSubstring: String,
202+
maxReplacements: Int
203+
) -> String {
204+
var string = origin
205+
var ranges: [Range<String.Index>] = []
206+
var start = string.startIndex
207+
while start < string.endIndex,
208+
let range = string.range(of: substring, range: start..<string.endIndex) {
209+
ranges.append(range)
210+
start = range.upperBound
211+
if ranges.count == maxReplacements { break }
212+
}
213+
214+
for range in ranges.reversed() {
215+
string.replaceSubrange(range, with: replacementSubstring)
216+
}
217+
return string
218+
}
186219
}
187220

188221
#endif

0 commit comments

Comments
 (0)