зеркало из https://github.com/microsoft/reactxp.git
Adding the ability to trigger layout change (on web) explicitly. (#74)
This commit is contained in:
Родитель
0cd76421df
Коммит
43f5371ccf
|
@ -140,6 +140,9 @@ export abstract class UserInterface {
|
|||
|
||||
// On-screen Keyboard
|
||||
abstract dismissKeyboard(): void;
|
||||
|
||||
// Explicit layout change indication
|
||||
abstract layoutChangePending(): void;
|
||||
}
|
||||
|
||||
export abstract class Modal {
|
||||
|
|
|
@ -121,6 +121,10 @@ export class UserInterface extends RX.UserInterface {
|
|||
renderMainView() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
layoutChangePending() {
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserInterface();
|
||||
|
|
|
@ -18,6 +18,8 @@ import RX = require('../common/Interfaces');
|
|||
import Types = require('../common/Types');
|
||||
|
||||
export class UserInterface extends RX.UserInterface {
|
||||
private _layoutChangeAnimationFrame: number;
|
||||
|
||||
measureLayoutRelativeToWindow(component: React.Component<any, any>) :
|
||||
SyncTasks.Promise<Types.LayoutInfo> {
|
||||
|
||||
|
@ -105,6 +107,19 @@ export class UserInterface extends RX.UserInterface {
|
|||
dismissKeyboard() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
layoutChangePending() {
|
||||
if (!this._layoutChangeAnimationFrame) {
|
||||
// ViewBase checks for the layout changes once a second or on window resize.
|
||||
// To avoid laggy layout updates we can indicate that there is a change pending.
|
||||
this._layoutChangeAnimationFrame = window.requestAnimationFrame(() => {
|
||||
this._layoutChangeAnimationFrame = undefined;
|
||||
let event = document.createEvent('HTMLEvents');
|
||||
event.initEvent('resize', true, false);
|
||||
window.dispatchEvent(event);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserInterface();
|
||||
|
|
Загрузка…
Ссылка в новой задаче