[TIMOB-18323] Windows: UI-related module should be notified when app window is ready
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-01-07T01:03:26.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Windows |
Labels | n/a |
Reporter | Ingo Muschenetz |
Assignee | Ingo Muschenetz |
Created | 2015-01-06T20:54:32.000+0000 |
Updated | 2017-03-14T19:13:22.000+0000 |
Description
Some UI-related modules like
Ti.Gesture
, Ti.Accelerometer
and Ti.Platform.DisplayCaps
needs reference to "current display information" (Windows::Graphics::Display::DisplayInformation
) to initialize internal state, but currently initializing it at module constructor is causing crash.
Let say we have Gesture
module and want to get current view after module is initialized, to initialize event listener. We could do it at constructor like below...
c++
Gesture::Gesture() {
// we want display information to initialize orientation event
const auto display = Windows::Graphics::Display::DisplayInformation::GetForCurrentView();
display->OrientationChanged += ....
}
Unfortunately, this ends up crash with following error. Note that WinRT complains about thread usage, but it is not quite right. Seems like problem here is that CoreWindow is not initialized at the moment.
WinRT information: Windows.Graphics.Display:
GetForCurrentView must be called on a thread that is associated with a CoreWindow.
So, what we actually need is "callback" which is called when window is ready. UI-related module should get notified after window is ready, so that it can setup UI-related stuff safely. It could be something like this:
// override
void Gesture::OnTitaniumMainWindowReady() {
// ok, now we can get current view safely
const auto display = Windows::Graphics::Display::DisplayInformation::GetForCurrentView
}
Fixed by PR #51
Closing ticket as fixed.