mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Pass the FlutterView to app message listeners (#2767)
This will make it simpler to write listeners that can be reused in multiple applications.
This commit is contained in:
parent
f8b2cca611
commit
471beb05aa
@ -610,7 +610,7 @@ public class FlutterView extends SurfaceView
|
||||
* Called when a message is received from the Flutter app.
|
||||
* @return the reply to the message (can be null)
|
||||
*/
|
||||
String onMessage(String message);
|
||||
String onMessage(FlutterView view, String message);
|
||||
};
|
||||
|
||||
public interface OnMessageListenerAsync {
|
||||
@ -618,7 +618,7 @@ public class FlutterView extends SurfaceView
|
||||
* Called when a message is received from the Flutter app.
|
||||
* @param response Used to send a reply back to the app.
|
||||
*/
|
||||
void onMessage(String message, MessageResponse response);
|
||||
void onMessage(FlutterView view, String message, MessageResponse response);
|
||||
}
|
||||
|
||||
public interface MessageResponse {
|
||||
@ -636,13 +636,13 @@ public class FlutterView extends SurfaceView
|
||||
public void sendString(String messageName, String message, SendStringResponse callback) {
|
||||
OnMessageListener listener = mOnMessageListeners.get(messageName);
|
||||
if (listener != null) {
|
||||
callback.call(listener.onMessage(message));
|
||||
callback.call(listener.onMessage(FlutterView.this, message));
|
||||
return;
|
||||
}
|
||||
|
||||
OnMessageListenerAsync asyncListener = mAsyncOnMessageListeners.get(messageName);
|
||||
if (asyncListener != null) {
|
||||
asyncListener.onMessage(message, new MessageResponseAdapter(callback));
|
||||
asyncListener.onMessage(FlutterView.this, message, new MessageResponseAdapter(callback));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user