mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Improve username setup
This commit is contained in:
parent
666b93af70
commit
dcf0ccf6eb
@ -5,6 +5,14 @@ import AsyncDisplayKit
|
|||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
import TelegramPresentationData
|
import TelegramPresentationData
|
||||||
|
|
||||||
|
private let validIdentifierSet: CharacterSet = {
|
||||||
|
var set = CharacterSet(charactersIn: "a".unicodeScalars.first! ... "z".unicodeScalars.first!)
|
||||||
|
set.insert(charactersIn: "A".unicodeScalars.first! ... "Z".unicodeScalars.first!)
|
||||||
|
set.insert(charactersIn: "0".unicodeScalars.first! ... "9".unicodeScalars.first!)
|
||||||
|
set.insert("_")
|
||||||
|
return set
|
||||||
|
}()
|
||||||
|
|
||||||
public enum ItemListSingleLineInputItemType: Equatable {
|
public enum ItemListSingleLineInputItemType: Equatable {
|
||||||
case regular(capitalization: Bool, autocorrection: Bool)
|
case regular(capitalization: Bool, autocorrection: Bool)
|
||||||
case password
|
case password
|
||||||
@ -503,7 +511,21 @@ public class ItemListSingleLineInputItemNode: ListViewItemNode, UITextFieldDeleg
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let item = self.item, case .username = item.type {
|
if let item = self.item, case .username = item.type {
|
||||||
let cleanString = string.folding(options: .diacriticInsensitive, locale: .current).replacingOccurrences(of: " ", with: "_")
|
var cleanString = string.folding(options: .diacriticInsensitive, locale: .current).replacingOccurrences(of: " ", with: "_")
|
||||||
|
|
||||||
|
let filtered = cleanString.unicodeScalars.filter { validIdentifierSet.contains($0) }
|
||||||
|
let filteredString = String(String.UnicodeScalarView(filtered))
|
||||||
|
|
||||||
|
if cleanString != filteredString {
|
||||||
|
cleanString = filteredString
|
||||||
|
|
||||||
|
let hapticFeedback = HapticFeedback()
|
||||||
|
hapticFeedback.error()
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0, execute: {
|
||||||
|
let _ = hapticFeedback
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if cleanString != string {
|
if cleanString != string {
|
||||||
var text = textField.text ?? ""
|
var text = textField.text ?? ""
|
||||||
text.replaceSubrange(text.index(text.startIndex, offsetBy: range.lowerBound) ..< text.index(text.startIndex, offsetBy: range.upperBound), with: cleanString)
|
text.replaceSubrange(text.index(text.startIndex, offsetBy: range.lowerBound) ..< text.index(text.startIndex, offsetBy: range.upperBound), with: cleanString)
|
||||||
|
@ -61,7 +61,7 @@ const CGFloat TGPhotoPaintSettingsPadPickerWidth = 360.0f;
|
|||||||
_eyedropperButton.exclusiveTouch = true;
|
_eyedropperButton.exclusiveTouch = true;
|
||||||
[_eyedropperButton setImage:TGTintedImage([UIImage imageNamed:@"Editor/Eyedropper"], [UIColor whiteColor]) forState:UIControlStateNormal];
|
[_eyedropperButton setImage:TGTintedImage([UIImage imageNamed:@"Editor/Eyedropper"], [UIColor whiteColor]) forState:UIControlStateNormal];
|
||||||
[_eyedropperButton addTarget:self action:@selector(eyedropperButtonPressed) forControlEvents:UIControlEventTouchUpInside];
|
[_eyedropperButton addTarget:self action:@selector(eyedropperButtonPressed) forControlEvents:UIControlEventTouchUpInside];
|
||||||
// [self addSubview:_eyedropperButton];
|
[self addSubview:_eyedropperButton];
|
||||||
|
|
||||||
_settingsButton = [[TGModernButton alloc] initWithFrame:CGRectMake(0, 0, 44.0f, 44.0f)];
|
_settingsButton = [[TGModernButton alloc] initWithFrame:CGRectMake(0, 0, 44.0f, 44.0f)];
|
||||||
_settingsButton.exclusiveTouch = true;
|
_settingsButton.exclusiveTouch = true;
|
||||||
@ -211,8 +211,7 @@ const CGFloat TGPhotoPaintSettingsPadPickerWidth = 360.0f;
|
|||||||
|
|
||||||
- (void)layoutSubviews
|
- (void)layoutSubviews
|
||||||
{
|
{
|
||||||
CGFloat leftInset = 23.0f;
|
CGFloat inset = 66.0f;
|
||||||
CGFloat rightInset = 66.0f;
|
|
||||||
CGFloat colorPickerHeight = 10.0f;
|
CGFloat colorPickerHeight = 10.0f;
|
||||||
if (self.frame.size.width > self.frame.size.height)
|
if (self.frame.size.width > self.frame.size.height)
|
||||||
{
|
{
|
||||||
@ -223,14 +222,14 @@ const CGFloat TGPhotoPaintSettingsPadPickerWidth = 360.0f;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_colorPicker.frame = CGRectMake(leftInset, ceil((self.frame.size.height - colorPickerHeight) / 2.0f), self.frame.size.width - leftInset - rightInset, colorPickerHeight);
|
_colorPicker.frame = CGRectMake(inset, ceil((self.frame.size.height - colorPickerHeight) / 2.0f), self.frame.size.width - inset - inset, colorPickerHeight);
|
||||||
_eyedropperButton.frame = CGRectMake(10.0f, floor((self.frame.size.height - _eyedropperButton.frame.size.height) / 2.0f) + 1.0f, _eyedropperButton.frame.size.width, _eyedropperButton.frame.size.height);
|
_eyedropperButton.frame = CGRectMake(10.0f, floor((self.frame.size.height - _eyedropperButton.frame.size.height) / 2.0f) + 1.0f, _eyedropperButton.frame.size.width, _eyedropperButton.frame.size.height);
|
||||||
_settingsButton.frame = CGRectMake(self.frame.size.width - _settingsButton.frame.size.width - 10.0f, floor((self.frame.size.height - _settingsButton.frame.size.height) / 2.0f) + 1.0f, _settingsButton.frame.size.width, _settingsButton.frame.size.height);
|
_settingsButton.frame = CGRectMake(self.frame.size.width - _settingsButton.frame.size.width - 10.0f, floor((self.frame.size.height - _settingsButton.frame.size.height) / 2.0f) + 1.0f, _settingsButton.frame.size.width, _settingsButton.frame.size.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_colorPicker.frame = CGRectMake(ceil((self.frame.size.width - colorPickerHeight) / 2.0f), rightInset, colorPickerHeight, self.frame.size.height - leftInset - rightInset);
|
_colorPicker.frame = CGRectMake(ceil((self.frame.size.width - colorPickerHeight) / 2.0f), inset, colorPickerHeight, self.frame.size.height - inset - inset);
|
||||||
_eyedropperButton.frame = CGRectMake(floor((self.frame.size.width - _eyedropperButton.frame.size.width) / 2.0f), self.frame.size.height - _eyedropperButton.frame.size.height - 10.0, _eyedropperButton.frame.size.width, _eyedropperButton.frame.size.height);
|
_eyedropperButton.frame = CGRectMake(floor((self.frame.size.width - _eyedropperButton.frame.size.width) / 2.0f), self.frame.size.height - _eyedropperButton.frame.size.height - 10.0, _eyedropperButton.frame.size.width, _eyedropperButton.frame.size.height);
|
||||||
_settingsButton.frame = CGRectMake(floor((self.frame.size.width - _settingsButton.frame.size.width) / 2.0f), 10.0f, _settingsButton.frame.size.width, _settingsButton.frame.size.height);
|
_settingsButton.frame = CGRectMake(floor((self.frame.size.width - _settingsButton.frame.size.width) / 2.0f), 10.0f, _settingsButton.frame.size.width, _settingsButton.frame.size.height);
|
||||||
}
|
}
|
||||||
|
@ -232,6 +232,7 @@ public func usernameSetupController(context: AccountContext) -> ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dismissImpl: (() -> Void)?
|
var dismissImpl: (() -> Void)?
|
||||||
|
var dismissInputImpl: (() -> Void)?
|
||||||
var presentControllerImpl: ((ViewController, Any?) -> Void)?
|
var presentControllerImpl: ((ViewController, Any?) -> Void)?
|
||||||
|
|
||||||
let actionsDisposable = DisposableSet()
|
let actionsDisposable = DisposableSet()
|
||||||
@ -277,6 +278,7 @@ public func usernameSetupController(context: AccountContext) -> ViewController {
|
|||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
if !currentAddressName.isEmpty {
|
if !currentAddressName.isEmpty {
|
||||||
|
dismissInputImpl?()
|
||||||
presentControllerImpl?(ShareController(context: context, subject: .url("https://t.me/\(currentAddressName)")), nil)
|
presentControllerImpl?(ShareController(context: context, subject: .url("https://t.me/\(currentAddressName)")), nil)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -354,6 +356,9 @@ public func usernameSetupController(context: AccountContext) -> ViewController {
|
|||||||
controller?.view.endEditing(true)
|
controller?.view.endEditing(true)
|
||||||
controller?.dismiss()
|
controller?.dismiss()
|
||||||
}
|
}
|
||||||
|
dismissInputImpl = { [weak controller] in
|
||||||
|
controller?.view.endEditing(true)
|
||||||
|
}
|
||||||
presentControllerImpl = { [weak controller] c, a in
|
presentControllerImpl = { [weak controller] c, a in
|
||||||
controller?.present(c, in: .window(.root), with: a)
|
controller?.present(c, in: .window(.root), with: a)
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ final class ChatTitleView: UIView, NavigationBarTitleView {
|
|||||||
}
|
}
|
||||||
latestIndex = range.upperBound
|
latestIndex = range.upperBound
|
||||||
|
|
||||||
let part = String(rawText[rawText.index(rawText.startIndex, offsetBy: lowerSegmentIndex) ..< rawText.index(rawText.startIndex, offsetBy: range.upperBound)])
|
let part = String(rawText[rawText.index(rawText.startIndex, offsetBy: lowerSegmentIndex) ..< rawText.index(rawText.startIndex, offsetBy: min(rawText.count, range.upperBound))])
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
segments.append(.number(count, NSAttributedString(string: part, font: textFont, textColor: textColor)))
|
segments.append(.number(count, NSAttributedString(string: part, font: textFont, textColor: textColor)))
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user