iOS: Trigger manual layout of root view controller when coming out of background
When rotating the device when the application is in the background iOS will ask the root view controller to layout its views when then foregrounding the application, but at that point the application state is still in the suspended state, meaning we block any view resizing or rendering. To ensure the views are resized correctly, we trigger a manual layout after the application comes out of the suspended state. Task-number: QTBUG-67719 Change-Id: I1ef0a4133d4b94edaac7b0f3cb4e49e367eb76d4 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
a75f25a43f
commit
e0e1c7ec2d
@ -56,8 +56,8 @@ public:
|
||||
static Qt::ApplicationState toQtApplicationState(UIApplicationState state);
|
||||
|
||||
Q_SIGNALS:
|
||||
void applicationStateWillChange(Qt::ApplicationState);
|
||||
void applicationStateDidChange(Qt::ApplicationState);
|
||||
void applicationStateWillChange(Qt::ApplicationState oldState, Qt::ApplicationState newState);
|
||||
void applicationStateDidChange(Qt::ApplicationState oldState, Qt::ApplicationState newState);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -87,18 +87,18 @@ QIOSApplicationState::QIOSApplicationState()
|
||||
|
||||
void QIOSApplicationState::handleApplicationStateChanged(UIApplicationState uiState, const QString &reason)
|
||||
{
|
||||
Qt::ApplicationState state = toQtApplicationState(uiState);
|
||||
qCDebug(lcQpaApplication) << qPrintable(reason)
|
||||
<< "- moving from" << QGuiApplication::applicationState() << "to" << state;
|
||||
Qt::ApplicationState oldState = QGuiApplication::applicationState();
|
||||
Qt::ApplicationState newState = toQtApplicationState(uiState);
|
||||
qCDebug(lcQpaApplication) << qPrintable(reason) << "- moving from" << oldState << "to" << newState;
|
||||
|
||||
if (QIOSIntegration *integration = QIOSIntegration::instance()) {
|
||||
emit integration->applicationState.applicationStateWillChange(state);
|
||||
QWindowSystemInterface::handleApplicationStateChanged(state);
|
||||
emit integration->applicationState.applicationStateDidChange(state);
|
||||
qCDebug(lcQpaApplication) << "done moving to" << state;
|
||||
emit integration->applicationState.applicationStateWillChange(oldState, newState);
|
||||
QWindowSystemInterface::handleApplicationStateChanged(newState);
|
||||
emit integration->applicationState.applicationStateDidChange(oldState, newState);
|
||||
qCDebug(lcQpaApplication) << "done moving to" << newState;
|
||||
} else {
|
||||
qCDebug(lcQpaApplication) << "no platform integration yet, setting state directly";
|
||||
QGuiApplicationPrivate::applicationState = state;
|
||||
QGuiApplicationPrivate::applicationState = newState;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,18 +301,22 @@ bool QIOSContext::verifyGraphicsHardwareAvailability()
|
||||
static dispatch_once_t onceToken = 0;
|
||||
dispatch_once(&onceToken, ^{
|
||||
QIOSApplicationState *applicationState = &QIOSIntegration::instance()->applicationState;
|
||||
connect(applicationState, &QIOSApplicationState::applicationStateWillChange, [](Qt::ApplicationState state) {
|
||||
if (applicationBackgrounded && state != Qt::ApplicationSuspended) {
|
||||
connect(applicationState, &QIOSApplicationState::applicationStateWillChange,
|
||||
[](Qt::ApplicationState oldState, Qt::ApplicationState newState) {
|
||||
Q_UNUSED(oldState);
|
||||
if (applicationBackgrounded && newState != Qt::ApplicationSuspended) {
|
||||
qCDebug(lcQpaGLContext) << "app no longer backgrounded, rendering enabled";
|
||||
applicationBackgrounded = false;
|
||||
applicationBackgrounded = true;
|
||||
}
|
||||
});
|
||||
connect(applicationState, &QIOSApplicationState::applicationStateDidChange, [](Qt::ApplicationState state) {
|
||||
if (state != Qt::ApplicationSuspended)
|
||||
}
|
||||
);
|
||||
connect(applicationState, &QIOSApplicationState::applicationStateDidChange,
|
||||
[](Qt::ApplicationState oldState, Qt::ApplicationState newState) {
|
||||
Q_UNUSED(oldState);
|
||||
if (newState != Qt::ApplicationSuspended)
|
||||
return;
|
||||
|
||||
qCDebug(lcQpaGLContext) << "app backgrounded, rendering disabled";
|
||||
applicationBackgrounded = true;
|
||||
|
||||
// By the time we receive this signal the application has moved into
|
||||
// Qt::ApplactionStateSuspended, and all windows have been obscured,
|
||||
@ -323,7 +327,8 @@ bool QIOSContext::verifyGraphicsHardwareAvailability()
|
||||
glFinish();
|
||||
currentContext->doneCurrent();
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (applicationBackgrounded) {
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
QIOSIntegration();
|
||||
~QIOSIntegration();
|
||||
|
||||
void initialize() override;
|
||||
|
||||
bool hasCapability(Capability cap) const override;
|
||||
|
||||
QPlatformWindow *createPlatformWindow(QWindow *window) const override;
|
||||
|
@ -95,7 +95,10 @@ QIOSIntegration::QIOSIntegration()
|
||||
|
||||
// Set current directory to app bundle folder
|
||||
QDir::setCurrent(QString::fromUtf8([[[NSBundle mainBundle] bundlePath] UTF8String]));
|
||||
}
|
||||
|
||||
void QIOSIntegration::initialize()
|
||||
{
|
||||
UIScreen *mainScreen = [UIScreen mainScreen];
|
||||
NSMutableArray *screens = [[[UIScreen screens] mutableCopy] autorelease];
|
||||
if (![screens containsObject:mainScreen]) {
|
||||
|
@ -273,6 +273,20 @@
|
||||
m_focusWindowChangeConnection = QObject::connect(qApp, &QGuiApplication::focusWindowChanged, [self]() {
|
||||
[self updateProperties];
|
||||
});
|
||||
|
||||
QIOSApplicationState *applicationState = &QIOSIntegration::instance()->applicationState;
|
||||
QObject::connect(applicationState, &QIOSApplicationState::applicationStateDidChange,
|
||||
[self](Qt::ApplicationState oldState, Qt::ApplicationState newState) {
|
||||
if (oldState == Qt::ApplicationSuspended && newState != Qt::ApplicationSuspended) {
|
||||
// We may have ignored an earlier layout because the application was suspended,
|
||||
// and we didn't want to render anything at that moment in fear of being killed
|
||||
// due to rendering in the background, so we trigger an explicit layout when
|
||||
// coming out of the suspended state.
|
||||
qCDebug(lcQpaWindow) << "triggering root VC layout when coming out of suspended state";
|
||||
[self.view setNeedsLayout];
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
Loading…
Reference in New Issue
Block a user