Fix keyboard

This commit is contained in:
Peter 2019-10-03 16:37:13 +04:00
parent ba3d2a2430
commit d27fb1fdce
22 changed files with 166 additions and 45 deletions

View File

@ -2574,8 +2574,6 @@
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
stopOnEveryThreadSanitizerIssue = "YES"
stopOnEveryMainThreadCheckerIssue = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable

View File

@ -50,8 +50,7 @@ private func fetchRawData(prefix: String) -> Signal<Data, FetchError> {
public func cloudDataAdditionalAddressSource(phoneNumber: Signal<String?, NoError>) -> Signal<MTBackupDatacenterData, NoError> {
return phoneNumber
|> take(1)
|> mapToSignal { _ -> Signal<MTBackupDatacenterData, NoError> in
let phoneNumber: String? = "7950"
|> mapToSignal { phoneNumber -> Signal<MTBackupDatacenterData, NoError> in
var prefix = ""
if let phoneNumber = phoneNumber, phoneNumber.count >= 1 {
prefix = String(phoneNumber[phoneNumber.startIndex ..< phoneNumber.index(after: phoneNumber.startIndex)])

View File

@ -83,7 +83,7 @@ private final class AuthorizationSequenceCountrySelectionNavigationContentNode:
self.addSubnode(self.searchBar)
self.searchBar.cancel = { [weak self] in
self?.searchBar.deactivate(clear: false)
//self?.searchBar.deactivate(clear: false)
self?.cancel()
}
@ -159,6 +159,8 @@ public final class AuthorizationSequenceCountrySelectionController: ViewControll
super.init(navigationBarPresentationData: NavigationBarPresentationData(theme: NavigationBarTheme(rootControllerTheme: theme), strings: NavigationBarStrings(presentationStrings: strings)))
self.navigationPresentation = .modal
self.statusBar.statusBarStyle = theme.rootController.statusBarStyle.style
let navigationContentNode = AuthorizationSequenceCountrySelectionNavigationContentNode(theme: theme, strings: strings, cancel: { [weak self] in
@ -191,7 +193,6 @@ public final class AuthorizationSequenceCountrySelectionController: ViewControll
override public func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.controllerNode.animateIn()
self.navigationContentNode?.activate()
}

View File

@ -111,7 +111,6 @@ final class AuthorizationSequenceCountrySelectionControllerNode: ASDisplayNode,
}
self.sections = sections
var sectionTitles = sections.map { $0.0 }
sectionTitles.insert(UITableView.indexSearch, at: 0)
self.sectionTitles = sectionTitles
super.init()

View File

@ -25,6 +25,7 @@ open class ActionSheetController: ViewController, PresentableController, Standal
super.init(navigationBarPresentationData: nil)
self.statusBar.statusBarStyle = .Ignore
self.blocksBackgroundWhenInOverlay = true
}

View File

@ -173,7 +173,11 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
topController.viewWillDisappear(true)
let topNode = topController.displayNode
bottomController.containerLayoutUpdated(layout.withUpdatedInputHeight(nil), transition: .immediate)
var bottomControllerLayout = layout
if bottomController.view.disableAutomaticKeyboardHandling.isEmpty {
bottomControllerLayout = bottomControllerLayout.withUpdatedInputHeight(nil)
}
bottomController.containerLayoutUpdated(bottomControllerLayout, transition: .immediate)
bottomController.viewWillAppear(true)
let bottomNode = bottomController.displayNode
@ -274,7 +278,11 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
} else {
transitionType = .pop
}
self.state.pending = PendingChild(value: self.makeChild(layout: layout.withUpdatedInputHeight(nil), value: last), transitionType: transitionType, transition: transition, update: { [weak self] pendingChild in
var updatedLayout = layout
if last.view.disableAutomaticKeyboardHandling.isEmpty {
updatedLayout = updatedLayout.withUpdatedInputHeight(nil)
}
self.state.pending = PendingChild(value: self.makeChild(layout: updatedLayout, value: last), transitionType: transitionType, transition: transition, update: { [weak self] pendingChild in
self?.pendingChildIsReady(pendingChild)
})
}
@ -289,7 +297,11 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
self.state.pending = nil
let previous = self.state.top
self.state.top = pending.value
self.topTransition(from: previous, to: pending.value, transitionType: pending.transitionType, layout: layout.withUpdatedInputHeight(nil), transition: pending.transition)
var updatedLayout = layout
if pending.value.value.view.disableAutomaticKeyboardHandling.isEmpty {
updatedLayout = updatedLayout.withUpdatedInputHeight(nil)
}
self.topTransition(from: previous, to: pending.value, transitionType: pending.transitionType, layout: updatedLayout, transition: pending.transition)
statusBarTransition = pending.transition
if !self.isReady {
self.isReady = true
@ -307,7 +319,7 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
var updatedStatusBarStyle = self.statusBarStyle
if let top = self.state.top {
var updatedLayout = layout
if let topTransition = self.state.transition {
if let topTransition = self.state.transition, top.value.view.disableAutomaticKeyboardHandling.isEmpty {
updatedLayout = updatedLayout.withUpdatedInputHeight(nil)
}
self.applyLayout(layout: updatedLayout, to: top, isMaster: true, transition: transition)
@ -408,7 +420,10 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
}
private func makeChild(layout: ContainerViewLayout, value: ViewController) -> Child {
let updatedLayout = layout.withUpdatedInputHeight(nil)
var updatedLayout = layout
if value.view.disableAutomaticKeyboardHandling.isEmpty {
updatedLayout = updatedLayout.withUpdatedInputHeight(nil)
}
value.containerLayoutUpdated(updatedLayout, transition: .immediate)
return Child(value: value, layout: updatedLayout)
}
@ -430,7 +445,7 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
break
}
if updatedLayout.inputHeight != nil {
if !self.canHaveKeyboardFocus {
if !self.canHaveKeyboardFocus && child.value.view.disableAutomaticKeyboardHandling.isEmpty {
updatedLayout = updatedLayout.withUpdatedInputHeight(nil)
}
}
@ -439,7 +454,7 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
shouldSyncKeyboard = true
}
if updatedLayout.inputHeight != nil {
if updatedLayout.inputHeight != nil && child.value.view.disableAutomaticKeyboardHandling.isEmpty {
if !self.canHaveKeyboardFocus || self.ignoreInputHeight {
updatedLayout = updatedLayout.withUpdatedInputHeight(nil)
}

View File

@ -1078,7 +1078,7 @@ open class NavigationController: UINavigationController, ContainableController,
}
if let layout = self.validLayout {
self.containerLayoutUpdated(layout, transition: transition)
inCallStatusBar.updateState(statusBar: nil, withSafeInsets: false, inCallText: forceInCallStatusBarText, animated: false)
inCallStatusBar.updateState(statusBar: nil, withSafeInsets: !layout.safeInsets.top.isZero, inCallText: forceInCallStatusBarText, animated: false)
}
} else if let inCallStatusBar = self.inCallStatusBar {
self.inCallStatusBar = nil

View File

@ -52,8 +52,6 @@ final class InstantPageReferenceController: ViewController {
override public func loadView() {
super.loadView()
self.statusBar.removeFromSupernode()
}
override public func viewDidAppear(_ animated: Bool) {

View File

@ -31,6 +31,8 @@ public final class JoinLinkPreviewController: ViewController {
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
super.init(navigationBarPresentationData: nil)
self.statusBar.statusBarStyle = .Ignore
}
required public init(coder aDecoder: NSCoder) {
@ -76,8 +78,6 @@ public final class JoinLinkPreviewController: ViewController {
override public func loadView() {
super.loadView()
self.statusBar.removeFromSupernode()
}
override public func viewDidAppear(_ animated: Bool) {

View File

@ -30,6 +30,8 @@ public final class LanguageLinkPreviewController: ViewController {
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
super.init(navigationBarPresentationData: nil)
self.statusBar.statusBarStyle = .Ignore
}
required public init(coder aDecoder: NSCoder) {
@ -85,8 +87,6 @@ public final class LanguageLinkPreviewController: ViewController {
override public func loadView() {
super.loadView()
self.statusBar.removeFromSupernode()
}
override public func viewDidAppear(_ animated: Bool) {

View File

@ -739,7 +739,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[UIView animateWithDuration:0.3f animations:^
{
[_context setApplicationStatusBarAlpha:1.0f];
//[_context setApplicationStatusBarAlpha:1.0f];
}];
}
@ -1816,7 +1816,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[UIView animateWithDuration:0.3f animations:^
{
[_context setApplicationStatusBarAlpha:1.0f];
//[_context setApplicationStatusBarAlpha:1.0f];
}];
[self setInterfaceHidden:true animated:true];
@ -1892,7 +1892,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
{
_finishedWithResult = true;
[_context setApplicationStatusBarAlpha:1.0f];
//[_context setApplicationStatusBarAlpha:1.0f];
self.view.hidden = true;

View File

@ -71,19 +71,23 @@ static NSData *base64_decode(NSString *str) {
+ (MTSignal *)fetchBackupIpsResolveGoogle:(bool)isTesting phoneNumber:(NSString *)phoneNumber currentContext:(MTContext *)currentContext addressOverride:(NSString *)addressOverride {
NSArray *hosts = @[
@"google.com",
@"www.google.com",
@"google.ru"
@[@"dns.google.com", @""],
@[@"www.google.com", @"dns.google.com"],
];
NSDictionary *headers = @{@"Host": @"dns.google.com"};
NSMutableArray *signals = [[NSMutableArray alloc] init];
for (NSString *host in hosts) {
for (NSArray *hostAndHostname in hosts) {
NSString *host = hostAndHostname[0];
NSString *hostName = hostAndHostname[1];
NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
if ([hostName length] != 0) {
headers[@"Host"] = hostName;
}
NSString *apvHost = @"apv3.stel.com";
if (addressOverride != nil) {
apvHost = addressOverride;
}
MTSignal *signal = [[[MTHttpRequestOperation dataForHttpUrl:[NSURL URLWithString:[NSString stringWithFormat:@"https://%@/resolve?name=%@&type=16", host, isTesting ? @"tapv3.stel.com" : apvHost]] headers:headers] mapToSignal:^MTSignal *(NSData *data) {
MTSignal *signal = [[[MTHttpRequestOperation dataForHttpUrl:[NSURL URLWithString:[NSString stringWithFormat:@"https://%@/resolve?name=%@&type=16&random_padding=%@", host, isTesting ? @"tapv3.stel.com" : apvHost, makeRandomPadding()]] headers:headers] mapToSignal:^MTSignal *(NSData *data) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([dict respondsToSelector:@selector(objectForKey:)]) {
NSArray *answer = dict[@"Answer"];
@ -132,6 +136,90 @@ static NSData *base64_decode(NSString *str) {
return [[MTSignal mergeSignals:signals] take:1];
}
static NSString *makeRandomPadding() {
char validCharacters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int maxIndex = sizeof(validCharacters) - 1;
int minPadding = 13;
int maxPadding = 128;
int padding = minPadding + arc4random_uniform(maxPadding - minPadding);
NSMutableData *result = [[NSMutableData alloc] initWithLength:padding];
for (NSUInteger i = 0; i < result.length; i++) {
int index = arc4random_uniform(maxIndex);
assert(index >= 0 && index < maxIndex);
((uint8_t *)(result.mutableBytes))[i] = validCharacters[index];
}
NSString *string = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
return string;
}
+ (MTSignal *)fetchBackupIpsResolveCloudflare:(bool)isTesting phoneNumber:(NSString *)phoneNumber currentContext:(MTContext *)currentContext addressOverride:(NSString *)addressOverride {
NSArray *hosts = @[
@[@"mozilla.cloudflare-dns.com", @""],
];
NSMutableArray *signals = [[NSMutableArray alloc] init];
for (NSArray *hostAndHostname in hosts) {
NSString *host = hostAndHostname[0];
NSString *hostName = hostAndHostname[1];
NSMutableDictionary *headers = [[NSMutableDictionary alloc] init];
headers[@"accept"] = @"application/dns-json";
if ([hostName length] != 0) {
headers[@"Host"] = hostName;
}
NSString *apvHost = @"apv3.stel.com";
if (addressOverride != nil) {
apvHost = addressOverride;
}
MTSignal *signal = [[[MTHttpRequestOperation dataForHttpUrl:[NSURL URLWithString:[NSString stringWithFormat:@"https://%@/dns-query?name=%@&type=16&random_padding=%@", host, isTesting ? @"tapv3.stel.com" : apvHost, makeRandomPadding()]] headers:headers] mapToSignal:^MTSignal *(NSData *data) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([dict respondsToSelector:@selector(objectForKey:)]) {
NSArray *answer = dict[@"Answer"];
NSMutableArray *strings = [[NSMutableArray alloc] init];
if ([answer respondsToSelector:@selector(objectAtIndex:)]) {
for (NSDictionary *value in answer) {
if ([value respondsToSelector:@selector(objectForKey:)]) {
NSString *part = value[@"data"];
if ([part respondsToSelector:@selector(characterAtIndex:)]) {
[strings addObject:part];
}
}
}
[strings sortUsingComparator:^NSComparisonResult(NSString *lhs, NSString *rhs) {
if (lhs.length > rhs.length) {
return NSOrderedAscending;
} else {
return NSOrderedDescending;
}
}];
NSString *finalString = @"";
for (NSString *string in strings) {
finalString = [finalString stringByAppendingString:[string stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"="]]];
}
NSData *result = base64_decode(finalString);
NSMutableData *finalData = [[NSMutableData alloc] initWithData:result];
[finalData setLength:256];
MTBackupDatacenterData *datacenterData = MTIPDataDecode(finalData, phoneNumber);
if (datacenterData != nil && [self checkIpData:datacenterData timestamp:(int32_t)[currentContext globalTime] source:@"resolveCloudflare"]) {
return [MTSignal single:datacenterData];
}
}
}
return [MTSignal complete];
}] catch:^MTSignal *(__unused id error) {
return [MTSignal complete];
}];
if (signals.count != 0) {
signal = [signal delay:signals.count onQueue:[[MTQueue alloc] init]];
}
[signals addObject:signal];
}
return [[MTSignal mergeSignals:signals] take:1];
}
+ (MTSignal *)fetchConfigFromAddress:(MTBackupDatacenterAddress *)address currentContext:(MTContext *)currentContext {
MTApiEnvironment *apiEnvironment = [currentContext.apiEnvironment copy];
@ -209,12 +297,23 @@ static NSData *base64_decode(NSString *str) {
+ (MTSignal * _Nonnull)fetchBackupIps:(bool)isTestingEnvironment currentContext:(MTContext * _Nonnull)currentContext additionalSource:(MTSignal * _Nullable)additionalSource phoneNumber:(NSString * _Nullable)phoneNumber {
NSMutableArray *signals = [[NSMutableArray alloc] init];
[signals addObject:[self fetchBackupIpsResolveGoogle:isTestingEnvironment phoneNumber:phoneNumber currentContext:currentContext addressOverride:currentContext.apiEnvironment.accessHostOverride]];
//[signals addObject:[self fetchBackupIpsResolveGoogle:isTestingEnvironment phoneNumber:phoneNumber currentContext:currentContext addressOverride:currentContext.apiEnvironment.accessHostOverride]];
//[signals addObject:[self fetchBackupIpsResolveCloudflare:isTestingEnvironment phoneNumber:phoneNumber currentContext:currentContext addressOverride:currentContext.apiEnvironment.accessHostOverride]];
if (additionalSource != nil) {
/*#if DEBUG
[signals removeAllObjects];
#endif*/
[signals addObject:additionalSource];
[signals addObject:[additionalSource mapToSignal:^MTSignal *(MTBackupDatacenterData *datacenterData) {
if (![datacenterData isKindOfClass:[MTBackupDatacenterData class]]) {
return [MTSignal complete];
}
MTBackupDatacenterData *datacenterData = MTIPDataDecode(finalData, phoneNumber);
if (datacenterData != nil && [self checkIpData:datacenterData timestamp:(int32_t)[currentContext globalTime] source:@"resolveExternal"]) {
return [MTSignal single:datacenterData];
} else {
return [MTSignal complete];
}
}]];
}
return [[[MTSignal mergeSignals:signals] take:1] mapToSignal:^MTSignal *(MTBackupDatacenterData *data) {

View File

@ -36,7 +36,7 @@
[subscriber putCompletion];
} failure:^(__unused NSOperation *operation, __unused NSError *error)
{
[subscriber putError:nil];
[subscriber putError:error];
}];
[operation start];

View File

@ -447,7 +447,7 @@ func editSettingsController(context: AccountContext, currentName: ItemListAvatar
(controller?.navigationController as? NavigationController)?.pushViewController(value)
}
presentControllerImpl = { [weak controller] value, arguments in
controller?.present(value, in: .window(.root), with: arguments ?? ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
controller?.present(value, in: .window(.root), with: arguments)
}
dismissImpl = { [weak controller] in
let _ = (controller?.navigationController as? NavigationController)?.popViewController(animated: true)

View File

@ -203,6 +203,11 @@ public final class ShareController: ViewController {
return self.displayNode as! ShareControllerNode
}
private let _ready = Promise<Bool>()
override public var ready: Promise<Bool> {
return self._ready
}
private var animatedIn = false
private let sharedContext: SharedAccountContext
@ -242,6 +247,8 @@ public final class ShareController: ViewController {
super.init(navigationBarPresentationData: nil)
self.statusBar.statusBarStyle = .Ignore
switch subject {
case let .url(text):
self.defaultAction = ShareControllerAction(title: self.presentationData.strings.ShareMenu_CopyShareLink, action: { [weak self] in
@ -567,7 +574,7 @@ public final class ShareController: ViewController {
return .preparing
case let .done(items):
if let strongSelf = self, !items.isEmpty {
strongSelf.ready.set(.single(true))
strongSelf._ready.set(.single(true))
var activityItems: [Any] = []
for item in items {
switch item {
@ -632,13 +639,11 @@ public final class ShareController: ViewController {
strongSelf.controllerNode.updatePeers(account: strongSelf.currentAccount, switchableAccounts: strongSelf.switchableAccounts, peers: next.0, accountPeer: next.1, defaultAction: strongSelf.defaultAction)
}
}))
self.ready.set(self.controllerNode.ready.get())
self._ready.set(self.controllerNode.ready.get())
}
override public func loadView() {
super.loadView()
self.statusBar.removeFromSupernode()
}
override public func viewDidAppear(_ animated: Bool) {

View File

@ -500,7 +500,7 @@ func initializedNetwork(arguments: NetworkInitializationArguments, supplementary
context.setDiscoverBackupAddressListSignal(MTBackupAddressSignals.fetchBackupIps(testingEnvironment, currentContext: context, additionalSource: wrappedAdditionalSource, phoneNumber: phoneNumber))
#if DEBUG
//let _ = MTBackupAddressSignals.fetchBackupIps(testingEnvironment, currentContext: context, additionalSource: wrappedAdditionalSource, phoneNumber: phoneNumber).start(next: nil)
let _ = MTBackupAddressSignals.fetchBackupIps(testingEnvironment, currentContext: context, additionalSource: wrappedAdditionalSource, phoneNumber: phoneNumber).start(next: nil)
#endif
let mtProto = MTProto(context: context, datacenterId: datacenterId, usageCalculationInfo: usageCalculationInfo(basePath: basePath, category: nil))!

View File

@ -70,6 +70,8 @@ final class AuthorizationSequenceCodeEntryController: ViewController {
self.displayNode = AuthorizationSequenceCodeEntryControllerNode(strings: self.strings, theme: self.theme)
self.displayNodeDidLoad()
self.controllerNode.view.disableAutomaticKeyboardHandling = [.forward, .backward]
self.controllerNode.loginWithCode = { [weak self] code in
self?.continueWithCode(code)
}

View File

@ -74,6 +74,8 @@ final class AuthorizationSequencePasswordEntryController: ViewController {
self.displayNode = AuthorizationSequencePasswordEntryControllerNode(strings: self.strings, theme: self.theme)
self.displayNodeDidLoad()
self.controllerNode.view.disableAutomaticKeyboardHandling = [.forward, .backward]
self.controllerNode.loginWithCode = { [weak self] _ in
self?.nextPressed()
}

View File

@ -106,6 +106,9 @@ final class AuthorizationSequencePhoneEntryController: ViewController {
self.controllerNode.codeAndNumber = (code, name, number)
}
self.displayNodeDidLoad()
self.controllerNode.view.disableAutomaticKeyboardHandling = [.forward, .backward]
self.controllerNode.selectCountryCode = { [weak self] in
if let strongSelf = self {
let controller = AuthorizationSequenceCountrySelectionController(strings: strongSelf.strings, theme: strongSelf.theme)
@ -118,8 +121,7 @@ final class AuthorizationSequencePhoneEntryController: ViewController {
controller.dismissed = {
self?.controllerNode.activateInput()
}
strongSelf.controllerNode.view.endEditing(true)
strongSelf.present(controller, in: .window(.root))
strongSelf.push(controller)
}
}
self.controllerNode.checkPhone = { [weak self] in

View File

@ -93,6 +93,8 @@ final class AuthorizationSequenceSignUpController: ViewController {
})
self.displayNodeDidLoad()
self.controllerNode.view.disableAutomaticKeyboardHandling = [.forward, .backward]
self.controllerNode.signUpWithName = { [weak self] _, _ in
self?.nextPressed()
}

View File

@ -38,6 +38,8 @@ final class ChatScheduleTimeController: ViewController {
super.init(navigationBarPresentationData: nil)
self.statusBar.statusBarStyle = .Ignore
self.blocksBackgroundWhenInOverlay = true
self.presentationDataDisposable = (context.sharedContext.presentationData
@ -74,8 +76,6 @@ final class ChatScheduleTimeController: ViewController {
override public func loadView() {
super.loadView()
self.statusBar.removeFromSupernode()
}
override public func viewDidAppear(_ animated: Bool) {

View File

@ -79,8 +79,6 @@ final class OverlayAudioPlayerControllerImpl: ViewController, OverlayAudioPlayer
override public func loadView() {
super.loadView()
self.statusBar.removeFromSupernode()
}
override public func viewDidAppear(_ animated: Bool) {