Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 63c19ad

Browse files
committed
Add support for initializing and hidden to iOS and Android
1 parent 54d99c3 commit 63c19ad

File tree

13 files changed

+40
-138
lines changed

13 files changed

+40
-138
lines changed

lib/ui/hooks.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ void _updateUserSettingsData(String jsonData) {
6666
PlatformDispatcher.instance._updateUserSettingsData(jsonData);
6767
}
6868

69-
@pragma('vm:entry-point')
70-
void _updateInitialLifecycleState(String state) {
71-
PlatformDispatcher.instance._updateInitialLifecycleState(state);
72-
}
73-
7469
@pragma('vm:entry-point')
7570
void _updateSemanticsEnabled(bool enabled) {
7671
PlatformDispatcher.instance._updateSemanticsEnabled(enabled);

lib/ui/platform_dispatcher.dart

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -910,24 +910,7 @@ class PlatformDispatcher {
910910
/// It is used to initialize [SchedulerBinding.lifecycleState] at startup with
911911
/// any buffered lifecycle state events.
912912
String get initialLifecycleState {
913-
_initialLifecycleStateAccessed = true;
914-
return _initialLifecycleState;
915-
}
916-
917-
late String _initialLifecycleState;
918-
919-
/// Tracks if the initial state has been accessed. Once accessed, we will stop
920-
/// updating the [initialLifecycleState], as it is not the preferred way to
921-
/// access the state.
922-
bool _initialLifecycleStateAccessed = false;
923-
924-
// Called from the engine, via hooks.dart
925-
void _updateInitialLifecycleState(String state) {
926-
// We do not update the state if the state has already been used to initialize
927-
// the lifecycleState.
928-
if (!_initialLifecycleStateAccessed) {
929-
_initialLifecycleState = state;
930-
}
913+
return AppLifecycleState.detached.toString();
931914
}
932915

933916
/// The setting indicating whether time should always be shown in the 24-hour

lib/ui/window/platform_configuration.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ void PlatformConfiguration::DidCreateIsolate() {
4848
update_user_settings_data_.Set(
4949
tonic::DartState::Current(),
5050
Dart_GetField(library, tonic::ToDart("_updateUserSettingsData")));
51-
update_initial_lifecycle_state_.Set(
52-
tonic::DartState::Current(),
53-
Dart_GetField(library, tonic::ToDart("_updateInitialLifecycleState")));
5451
update_semantics_enabled_.Set(
5552
tonic::DartState::Current(),
5653
Dart_GetField(library, tonic::ToDart("_updateSemanticsEnabled")));
@@ -108,20 +105,6 @@ void PlatformConfiguration::UpdateUserSettingsData(const std::string& data) {
108105
}));
109106
}
110107

111-
void PlatformConfiguration::UpdateInitialLifecycleState(
112-
const std::string& data) {
113-
std::shared_ptr<tonic::DartState> dart_state =
114-
update_initial_lifecycle_state_.dart_state().lock();
115-
if (!dart_state) {
116-
return;
117-
}
118-
tonic::DartState::Scope scope(dart_state);
119-
tonic::CheckAndHandleError(tonic::DartInvoke(
120-
update_initial_lifecycle_state_.Get(), {
121-
tonic::StdStringToDart(data),
122-
}));
123-
}
124-
125108
void PlatformConfiguration::UpdateSemanticsEnabled(bool enabled) {
126109
std::shared_ptr<tonic::DartState> dart_state =
127110
update_semantics_enabled_.dart_state().lock();

lib/ui/window/platform_configuration.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,6 @@ class PlatformConfiguration final {
288288
///
289289
void UpdateUserSettingsData(const std::string& data);
290290

291-
//----------------------------------------------------------------------------
292-
/// @brief Updates the lifecycle state data in the framework.
293-
///
294-
/// @deprecated The persistent isolate data must be used for this purpose
295-
/// instead.
296-
///
297-
/// @param[in] data The lifecycle state data.
298-
///
299-
void UpdateInitialLifecycleState(const std::string& data);
300-
301291
//----------------------------------------------------------------------------
302292
/// @brief Notifies the PlatformConfiguration that the embedder has
303293
/// expressed an opinion about whether the accessibility tree
@@ -436,7 +426,6 @@ class PlatformConfiguration final {
436426
tonic::DartPersistentValue on_error_;
437427
tonic::DartPersistentValue update_locales_;
438428
tonic::DartPersistentValue update_user_settings_data_;
439-
tonic::DartPersistentValue update_initial_lifecycle_state_;
440429
tonic::DartPersistentValue update_semantics_enabled_;
441430
tonic::DartPersistentValue update_accessibility_features_;
442431
tonic::DartPersistentValue dispatch_platform_message_;

runtime/runtime_controller.cc

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ bool RuntimeController::FlushRuntimeStateToIsolate() {
118118
SetSemanticsEnabled(platform_data_.semantics_enabled) &&
119119
SetAccessibilityFeatures(
120120
platform_data_.accessibility_feature_flags_) &&
121-
SetUserSettingsData(platform_data_.user_settings_data) &&
122-
SetInitialLifecycleState(platform_data_.lifecycle_state);
121+
SetUserSettingsData(platform_data_.user_settings_data);
123122
}
124123

125124
bool RuntimeController::SetViewportMetrics(const ViewportMetrics& metrics) {
@@ -157,18 +156,6 @@ bool RuntimeController::SetUserSettingsData(const std::string& data) {
157156
return false;
158157
}
159158

160-
bool RuntimeController::SetInitialLifecycleState(const std::string& data) {
161-
platform_data_.lifecycle_state = data;
162-
163-
if (auto* platform_configuration = GetPlatformConfigurationIfAvailable()) {
164-
platform_configuration->UpdateInitialLifecycleState(
165-
platform_data_.lifecycle_state);
166-
return true;
167-
}
168-
169-
return false;
170-
}
171-
172159
bool RuntimeController::SetSemanticsEnabled(bool enabled) {
173160
platform_data_.semantics_enabled = enabled;
174161

runtime/runtime_controller.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,6 @@ class RuntimeController : public PlatformConfigurationClient {
204204
///
205205
bool SetUserSettingsData(const std::string& data);
206206

207-
//----------------------------------------------------------------------------
208-
/// @brief Forward the initial lifecycle state data to the running
209-
/// isolate. If the isolate is not running, this data will be
210-
/// saved and flushed to the isolate when it starts running.
211-
/// After the isolate starts running, the current lifecycle
212-
/// state is pushed to it via the "flutter/lifecycle" channel.
213-
///
214-
/// @deprecated The persistent isolate data must be used for this purpose
215-
/// instead.
216-
///
217-
/// @param[in] data The lifecycle state data.
218-
///
219-
/// @return If the lifecycle state data was forwarded to the running
220-
/// isolate.
221-
///
222-
bool SetInitialLifecycleState(const std::string& data);
223-
224207
//----------------------------------------------------------------------------
225208
/// @brief Notifies the running isolate about whether the semantics tree
226209
/// should be generated or not. If the isolate is not running,

shell/common/engine.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ bool Engine::HandleLifecyclePlatformMessage(PlatformMessage* message) {
331331
state == "AppLifecycleState.inactive") {
332332
ScheduleFrame();
333333
}
334-
runtime_controller_->SetInitialLifecycleState(state);
335334
// Always forward these messages to the framework by returning false.
336335
return false;
337336
}

shell/platform/android/io/flutter/app/FlutterActivityDelegate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public void onCreate(Bundle savedInstanceState) {
159159
}
160160
}
161161

162+
flutterView.onCreate();
163+
162164
if (loadIntent(activity.getIntent())) {
163165
return;
164166
}

shell/platform/android/io/flutter/embedding/engine/systemchannels/LifecycleChannel.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ public class LifecycleChannel {
1919
public LifecycleChannel(@NonNull DartExecutor dartExecutor) {
2020
this.channel =
2121
new BasicMessageChannel<>(dartExecutor, "flutter/lifecycle", StringCodec.INSTANCE);
22+
this.channel.resizeChannelBuffer(1000);
23+
}
24+
25+
public void appIsHidden() {
26+
Log.v(TAG, "Sending AppLifecycleState.hidden message.");
27+
channel.send("AppLifecycleState.hidden");
28+
}
29+
30+
public void appIsInitializing() {
31+
Log.v(TAG, "Sending AppLifecycleState.initializing message.");
32+
channel.send("AppLifecycleState.initializing");
2233
}
2334

2435
public void appIsInactive() {

shell/platform/android/io/flutter/view/FlutterView.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ public void addActivityLifecycleListener(ActivityLifecycleListener listener) {
297297
mActivityLifecycleListeners.add(listener);
298298
}
299299

300+
public void onCreate() {
301+
lifecycleChannel.appIsInitializing();
302+
}
303+
300304
public void onStart() {
305+
lifecycleChannel.appIsHidden();
301306
lifecycleChannel.appIsInactive();
302307
}
303308

@@ -313,6 +318,7 @@ public void onPostResume() {
313318
}
314319

315320
public void onStop() {
321+
lifecycleChannel.appIsHidden();
316322
lifecycleChannel.appIsPaused();
317323
}
318324

0 commit comments

Comments
 (0)