浏览代码

Merge branch 'kgdev' into 'master'

using (WindowProvider.of(BuildContext).getScope())

See merge request upm-packages/ui-widgets/com.unity.uiwidgets!104
/main
Fan Zhang 6 年前
当前提交
c23ed054
共有 4 个文件被更改,包括 35 次插入41 次删除
  1. 27
      Runtime/editor/editor_window.cs
  2. 27
      Runtime/scheduler/binding.cs
  3. 12
      Runtime/ui/window.cs
  4. 10
      Runtime/widgets/framework.cs

27
Runtime/editor/editor_window.cs


using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;

}
}
WidgetsBinding _binding;
internal WidgetsBinding _binding;
float _lastWindowWidth;
float _lastWindowHeight;

}
public override IDisposable getScope() {
instance = this;
WindowAdapter oldInstance = (WindowAdapter) Window._instance;
Window._instance = this;
}
WidgetsBinding.instance = this._binding;
return new WindowDisposable(this);
}
SchedulerBinding._instance = this._binding;
return new WindowDisposable(this, oldInstance);
readonly WindowAdapter _oldWindow;
public WindowDisposable(WindowAdapter window) {
public WindowDisposable(WindowAdapter window, WindowAdapter oldWindow) {
this._oldWindow = oldWindow;
D.assert(instance == this._window);
instance = null;
D.assert(Window._instance == this._window);
Window._instance = this._oldWindow;
D.assert(WidgetsBinding.instance == this._window._binding);
WidgetsBinding.instance = null;
D.assert(SchedulerBinding._instance == this._window._binding);
SchedulerBinding._instance = this._oldWindow?._binding;
}
}

27
Runtime/scheduler/binding.cs


return true;
});
this.debugStack = debugCurrentCallbackStack;
}
else {
} else {
this.debugStack = new StackTrace(2, true);
}

public class SchedulerBinding {
public static SchedulerBinding instance {
get {
D.assert(_instance != null, "Binding.instance is null");
D.assert(_instance != null,
"Binding.instance is null. " +
"This usually happens when there is a callback from outside of UIWidgets. " +
"Try to use \"using (WindowProvider.of(BuildContext).getScope()) { ... }\" to wrap your code.");
return _instance;
}

_instance = null;
}
else {
} else {
D.assert(_instance == null, "Binding.instance is already assigned.");
_instance = value;
}

static SchedulerBinding _instance;
internal static SchedulerBinding _instance;
public SchedulerBinding() {
Window.instance.onBeginFrame += this._handleBeginFrame;

if (rawTimeStamp != null) {
_debugDescribeTimeStamp(
this._currentFrameTimeStamp.Value, frameTimeStampDescription);
}
else {
} else {
frameTimeStampDescription.Append("(warm-up frame)");
}

}
this._removedIds.Clear();
}
finally {
} finally {
this._schedulerPhase = SchedulerPhase.midFrameMicrotasks;
}
}

foreach (FrameCallback callback in localPostFrameCallbacks) {
this._invokeFrameCallback(callback, this._currentFrameTimeStamp.Value);
}
}
finally {
} finally {
this._schedulerPhase = SchedulerPhase.idle;
D.assert(() => {
if (D.debugPrintEndFrameBanner) {

try {
callback(timeStamp);
}
catch (Exception ex) {
} catch (Exception ex) {
UIWidgetsError.reportError(new UIWidgetsErrorDetails(
exception: ex,
library: "scheduler library",

});
}
}
}
}

12
Runtime/ui/window.cs


public abstract class Window {
public static Window instance {
get {
D.assert(_instance != null, "Window.instance is null");
D.assert(_instance != null,
"Window.instance is null. " +
"This usually happens when there is a callback from outside of UIWidgets. " +
"Try to use \"using (WindowProvider.of(BuildContext).getScope()) { ... }\" to wrap your code.");
return _instance;
}

_instance = null;
}
else {
} else {
D.assert(_instance == null, "Window.instance is already assigned.");
_instance = value;
}

get { return _instance != null; }
}
static Window _instance;
internal static Window _instance;
public float devicePixelRatio {
get { return this._devicePixelRatio; }

public abstract IDisposable getScope();
}
}
}

10
Runtime/widgets/framework.cs


return true;
});
if (Window.hasInstance) {
this._setState(fn);
} else {
using (WindowProvider.of(this.context).getScope()) {
this._setState(fn);
}
}
}
void _setState(VoidCallback fn = null) {
if (fn != null) {
fn();
}

正在加载...
取消
保存