Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PlatformView.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.plugin.platform;
6
7import android.annotation.SuppressLint;
8import android.view.View;
9import androidx.annotation.NonNull;
10import androidx.annotation.Nullable;
11
12/** A handle to an Android view to be embedded in the Flutter hierarchy. */
13public interface PlatformView {
14 /** Returns the Android view to be embedded in the Flutter hierarchy. */
15 @Nullable
16 View getView();
17
18 /**
19 * Called by the {@link io.flutter.embedding.engine.FlutterEngine} that owns this {@code
20 * PlatformView} when the Android {@link View} responsible for rendering a Flutter UI is
21 * associated with the {@link io.flutter.embedding.engine.FlutterEngine}.
22 *
23 * <p>This means that our associated {@link io.flutter.embedding.engine.FlutterEngine} can now
24 * render a UI and interact with the user.
25 *
26 * <p>Some platform views may have unusual dependencies on the {@link View} that renders Flutter
27 * UIs, such as unique keyboard interactions. That {@link View} is provided here for those
28 * purposes. Use of this {@link View} should be avoided if it is not absolutely necessary, because
29 * depending on this {@link View} will tend to make platform view code more brittle to future
30 * changes.
31 */
32 // Default interface methods are supported on all min SDK versions of Android.
33 @SuppressLint("NewApi")
34 default void onFlutterViewAttached(@NonNull View flutterView) {}
35
36 /**
37 * Called by the {@link io.flutter.embedding.engine.FlutterEngine} that owns this {@code
38 * PlatformView} when the Android {@link View} responsible for rendering a Flutter UI is detached
39 * and disassociated from the {@link io.flutter.embedding.engine.FlutterEngine}.
40 *
41 * <p>This means that our associated {@link io.flutter.embedding.engine.FlutterEngine} no longer
42 * has a rendering surface, or a user interaction surface of any kind.
43 *
44 * <p>This platform view must release any references related to the Android {@link View} that was
45 * provided in {@link #onFlutterViewAttached(View)}.
46 */
47 // Default interface methods are supported on all min SDK versions of Android.
48 @SuppressLint("NewApi")
49 default void onFlutterViewDetached() {}
50
51 /**
52 * Dispose this platform view.
53 *
54 * <p>The {@link PlatformView} object is unusable after this method is called.
55 *
56 * <p>Plugins implementing {@link PlatformView} must clear all references to the View object and
57 * the PlatformView after this method is called. Failing to do so will result in a memory leak.
58 *
59 * <p>References related to the Android {@link View} attached in {@link
60 * #onFlutterViewAttached(View)} must be released in {@code dispose()} to avoid memory leaks.
61 */
62 void dispose();
63
64 /**
65 * Callback fired when the platform's input connection is locked, or should be used.
66 *
67 * <p>This hook only exists for rare cases where the plugin relies on the state of the input
68 * connection. This probably doesn't need to be implemented.
69 */
70 @SuppressLint("NewApi")
71 default void onInputConnectionLocked() {}
72
73 /**
74 * Callback fired when the platform input connection has been unlocked.
75 *
76 * <p>This hook only exists for rare cases where the plugin relies on the state of the input
77 * connection. This probably doesn't need to be implemented.
78 */
79 @SuppressLint("NewApi")
80 default void onInputConnectionUnlocked() {}
81}
default void onFlutterViewAttached(@NonNull View flutterView)