hooks.dart 5.0 KB
Newer Older
M
Michael Goderbauer 已提交
1
// Copyright 2013 The Flutter Authors. All rights reserved.
A
Adam Barth 已提交
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// TODO(dnfield): Remove unused_import ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved.

7
// @dart = 2.10
8

A
Adam Barth 已提交
9
part of dart.ui;
A
Adam Barth 已提交
10

C
Chris Bracken 已提交
11
@pragma('vm:entry-point')
12
// ignore: unused_element
13
void _updateWindowMetrics(
14
  Object id,
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  double devicePixelRatio,
  double width,
  double height,
  double viewPaddingTop,
  double viewPaddingRight,
  double viewPaddingBottom,
  double viewPaddingLeft,
  double viewInsetTop,
  double viewInsetRight,
  double viewInsetBottom,
  double viewInsetLeft,
  double systemGestureInsetTop,
  double systemGestureInsetRight,
  double systemGestureInsetBottom,
  double systemGestureInsetLeft,
30
) {
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  PlatformDispatcher.instance._updateWindowMetrics(
    id,
    devicePixelRatio,
    width,
    height,
    viewPaddingTop,
    viewPaddingRight,
    viewPaddingBottom,
    viewPaddingLeft,
    viewInsetTop,
    viewInsetRight,
    viewInsetBottom,
    viewInsetLeft,
    systemGestureInsetTop,
    systemGestureInsetRight,
    systemGestureInsetBottom,
    systemGestureInsetLeft,
  );
49 50
}

51 52
typedef _LocaleClosure = String Function();

C
Chris Bracken 已提交
53
@pragma('vm:entry-point')
54
// ignore: unused_element
55
_LocaleClosure? _getLocaleClosure() => PlatformDispatcher.instance._localeClosure;
56

C
Chris Bracken 已提交
57
@pragma('vm:entry-point')
58
// ignore: unused_element
59
void _updateLocales(List<String> locales) {
60
  PlatformDispatcher.instance._updateLocales(locales);
61 62
}

C
Chris Bracken 已提交
63
@pragma('vm:entry-point')
64
// ignore: unused_element
65
void _updateUserSettingsData(String jsonData) {
66
  PlatformDispatcher.instance._updateUserSettingsData(jsonData);
67 68
}

69 70
@pragma('vm:entry-point')
// ignore: unused_element
71
void _updateLifecycleState(String state) {
72
  PlatformDispatcher.instance._updateLifecycleState(state);
73 74
}

C
Chris Bracken 已提交
75
@pragma('vm:entry-point')
76
// ignore: unused_element
77
void _updateSemanticsEnabled(bool enabled) {
78
  PlatformDispatcher.instance._updateSemanticsEnabled(enabled);
79 80
}

C
Chris Bracken 已提交
81
@pragma('vm:entry-point')
82
// ignore: unused_element
83
void _updateAccessibilityFeatures(int values) {
84
  PlatformDispatcher.instance._updateAccessibilityFeatures(values);
85 86
}

C
Chris Bracken 已提交
87
@pragma('vm:entry-point')
88
// ignore: unused_element
89
void _dispatchPlatformMessage(String name, ByteData? data, int responseId) {
90
  PlatformDispatcher.instance._dispatchPlatformMessage(name, data, responseId);
A
Adam Barth 已提交
91 92
}

C
Chris Bracken 已提交
93
@pragma('vm:entry-point')
94
// ignore: unused_element
95
void _dispatchPointerDataPacket(ByteData packet) {
96
  PlatformDispatcher.instance._dispatchPointerDataPacket(packet);
97 98
}

C
Chris Bracken 已提交
99
@pragma('vm:entry-point')
100
// ignore: unused_element
101
void _dispatchSemanticsAction(int id, int action, ByteData? args) {
102
  PlatformDispatcher.instance._dispatchSemanticsAction(id, action, args);
103 104
}

C
Chris Bracken 已提交
105
@pragma('vm:entry-point')
106
// ignore: unused_element
107
void _beginFrame(int microseconds) {
108
  PlatformDispatcher.instance._beginFrame(microseconds);
A
Adam Barth 已提交
109
}
110

111 112
@pragma('vm:entry-point')
// ignore: unused_element
113
void _reportTimings(List<int> timings) {
114
  PlatformDispatcher.instance._reportTimings(timings);
115 116
}

C
Chris Bracken 已提交
117
@pragma('vm:entry-point')
118
// ignore: unused_element
119
void _drawFrame() {
120
  PlatformDispatcher.instance._drawFrame();
Y
Yegor 已提交
121 122
}

123
// ignore: always_declare_return_types, prefer_generic_function_type_aliases
124
typedef _ListStringArgFunction(List<String> args);
125

C
Chris Bracken 已提交
126
@pragma('vm:entry-point')
127
// ignore: unused_element
128 129 130
void _runMainZoned(Function startMainIsolateFunction,
                   Function userMainFunction,
                   List<String> args) {
131
  startMainIsolateFunction(() {
132
    runZonedGuarded<void>(() {
133
      if (userMainFunction is _ListStringArgFunction) {
134
        (userMainFunction as dynamic)(args);
135 136 137
      } else {
        userMainFunction();
      }
138
    }, (Object error, StackTrace stackTrace) {
139 140 141 142 143
      _reportUnhandledException(error.toString(), stackTrace.toString());
    });
  }, null);
}

144
void _reportUnhandledException(String error, String stackTrace) native 'PlatformConfiguration_reportUnhandledException';
145

Y
Yegor 已提交
146
/// Invokes [callback] inside the given [zone].
147 148
void _invoke(void Function()? callback, Zone zone) {
  if (callback == null) {
Y
Yegor 已提交
149
    return;
150
  }
Y
Yegor 已提交
151

152
  assert(zone != null); // ignore: unnecessary_null_comparison
Y
Yegor 已提交
153 154 155 156 157 158 159 160 161

  if (identical(zone, Zone.current)) {
    callback();
  } else {
    zone.runGuarded(callback);
  }
}

/// Invokes [callback] inside the given [zone] passing it [arg].
162 163
void _invoke1<A>(void Function(A a)? callback, Zone zone, A arg) {
  if (callback == null) {
Y
Yegor 已提交
164
    return;
165
  }
Y
Yegor 已提交
166

167
  assert(zone != null); // ignore: unnecessary_null_comparison
Y
Yegor 已提交
168 169 170 171

  if (identical(zone, Zone.current)) {
    callback(arg);
  } else {
172
    zone.runUnaryGuarded<A>(callback, arg);
Y
Yegor 已提交
173 174 175
  }
}

176
/// Invokes [callback] inside the given [zone] passing it [arg1], [arg2], and [arg3].
177 178 179 180 181 182 183 184
void _invoke3<A1, A2, A3>(
  void Function(A1 a1, A2 a2, A3 a3)? callback,
  Zone zone,
  A1 arg1,
  A2 arg2,
  A3 arg3,
) {
  if (callback == null) {
Y
Yegor 已提交
185
    return;
186
  }
Y
Yegor 已提交
187

188
  assert(zone != null); // ignore: unnecessary_null_comparison
Y
Yegor 已提交
189 190 191 192 193 194 195 196

  if (identical(zone, Zone.current)) {
    callback(arg1, arg2, arg3);
  } else {
    zone.runGuarded(() {
      callback(arg1, arg2, arg3);
    });
  }
197
}