mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
fix observing SDL window's view creation on iOS 15
also improves observers handling fix kambala-decapitator/vcmi#38
This commit is contained in:
parent
fab3216df0
commit
5f24307ac8
@ -32,6 +32,8 @@ double ios_screenScale() { return UIScreen.mainScreen.nativeScale; }
|
|||||||
@implementation SDLViewObserver
|
@implementation SDLViewObserver
|
||||||
|
|
||||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
|
||||||
|
[object removeObserver:self forKeyPath:keyPath];
|
||||||
|
|
||||||
UIView * view = [object valueForKeyPath:keyPath];
|
UIView * view = [object valueForKeyPath:keyPath];
|
||||||
|
|
||||||
UITextField * textField;
|
UITextField * textField;
|
||||||
@ -127,22 +129,31 @@ int startSDL(int argc, char * argv[], BOOL startManually)
|
|||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
auto observer = [SDLViewObserver new];
|
auto observer = [SDLViewObserver new];
|
||||||
observer.gameChatHandler = [GameChatKeyboardHanlder new];
|
observer.gameChatHandler = [GameChatKeyboardHanlder new];
|
||||||
[NSNotificationCenter.defaultCenter addObserverForName:UIWindowDidBecomeKeyNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
|
|
||||||
[UIApplication.sharedApplication.keyWindow.rootViewController addObserver:observer forKeyPath:NSStringFromSelector(@selector(view)) options:NSKeyValueObservingOptionNew context:NULL];
|
id __block sdlWindowCreationObserver = [NSNotificationCenter.defaultCenter addObserverForName:UIWindowDidBecomeKeyNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
|
||||||
|
[NSNotificationCenter.defaultCenter removeObserver:sdlWindowCreationObserver];
|
||||||
|
sdlWindowCreationObserver = nil;
|
||||||
|
|
||||||
|
UIWindow * sdlWindow = note.object;
|
||||||
|
[sdlWindow.rootViewController addObserver:observer forKeyPath:NSStringFromSelector(@selector(view)) options:NSKeyValueObservingOptionNew context:NULL];
|
||||||
}];
|
}];
|
||||||
[NSNotificationCenter.defaultCenter addObserverForName:UITextFieldTextDidEndEditingNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
|
id textFieldObserver = [NSNotificationCenter.defaultCenter addObserverForName:UITextFieldTextDidEndEditingNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
|
||||||
removeFocusFromActiveInput();
|
removeFocusFromActiveInput();
|
||||||
}];
|
}];
|
||||||
|
|
||||||
if (!startManually)
|
int result;
|
||||||
return SDL_UIKitRunApp(argc, argv, SDL_main);
|
if (startManually)
|
||||||
|
{
|
||||||
// copied from -[SDLUIKitDelegate postFinishLaunch]
|
// copied from -[SDLUIKitDelegate postFinishLaunch]
|
||||||
SDL_SetMainReady();
|
SDL_SetMainReady();
|
||||||
SDL_iOSSetEventPump(SDL_TRUE);
|
SDL_iOSSetEventPump(SDL_TRUE);
|
||||||
auto result = SDL_main(argc, argv);
|
result = SDL_main(argc, argv);
|
||||||
SDL_iOSSetEventPump(SDL_FALSE);
|
SDL_iOSSetEventPump(SDL_FALSE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result = SDL_UIKitRunApp(argc, argv, SDL_main);
|
||||||
|
|
||||||
|
[NSNotificationCenter.defaultCenter removeObserver:textFieldObserver];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user