diff --git a/shell/platform/ohos/flutter_embedding/flutter/oh-package.json5 b/shell/platform/ohos/flutter_embedding/flutter/oh-package.json5 index 8c53bcea950310b995e8dbde1f7cce6675f36377..39bbaa64c01def1568782d0af4659f2391b78fad 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/oh-package.json5 +++ b/shell/platform/ohos/flutter_embedding/flutter/oh-package.json5 @@ -16,8 +16,8 @@ { "license": "Apache-2.0", "author": "", - "name": "flutter", - "description": "Please describe the basic information.", + "name": "@ohos/flutter_ohos", + "description": "The embedder of flutter in ohos.", "main": "index.ets", "version": "1.0.0", "dependencies": {}, diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets index 45a76fdda8da51301ac9dab19cd5cb37c46f391d..53a5eabeca7ef8c0b205a413100d8693733f1c4a 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets @@ -17,6 +17,7 @@ import common from '@ohos.app.ability.common'; import resourceManager from '@ohos.resourceManager'; import image from '@ohos.multimedia.image'; import FlutterNapi from '../../../ets/embedding/engine/FlutterNapi'; +import { FlutterCallbackInformation } from '../../../ets/view/FlutterCallbackInformation'; export const getContext: (a: number) => napiContext; @@ -132,3 +133,5 @@ export const nativeEncodeUtf8: (str: string) => Uint8Array; export const nativeDecodeUtf8: (array: Uint8Array) => string; export const nativeSetTextureBufferSize: (nativeShellHolderId: number, textureId: number, width: number, height: number) => void; + +export const nativeLookupCallbackInformation: (callback: FlutterCallbackInformation, handler: number) => number; \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets index 75f4a58b453dcc38d1af218a83b334dcd2efe144..78f1a520e7ec6efbc792f1164c8933dafc439d6d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets @@ -101,8 +101,8 @@ export default class FlutterNapi { runBundleAndSnapshotFromLibrary( bundlePath: string, - entrypointFunctionName: string, - pathToEntrypointFunction: string, + entrypointFunctionName: string | undefined, + pathToEntrypointFunction: string | undefined, assetManager: resourceManager.ResourceManager, entrypointArgs: Array) { if (!FlutterNapi.hasInit) { @@ -138,6 +138,11 @@ export default class FlutterNapi { } static nativeLookupCallbackInformation(handle: number): FlutterCallbackInformation | null { + let callbackInformation = new FlutterCallbackInformation(); + let ret : number = flutter.nativeLookupCallbackInformation(callbackInformation, handle); + if (ret == 0) { + return callbackInformation; + } return null; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets index 8afbc9222396e8c7c3437818b36f7c05469fb9cd..caf39c49165ef42fcd90c20e7c823f1a7eda01e9 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformChannel.ets @@ -321,7 +321,8 @@ class PlatformMethodCallback implements MethodCallHandler { case "SystemChrome.setApplicationSwitcherDescription": Log.d(PlatformMethodCallback.TAG, "setApplicationSwitcherDescription: " + JSON.stringify(args)); try { - this.platform.platformMessageHandler.setApplicationSwitcherDescription(args); + let description: AppSwitcherDescription = this.decodeAppSwitcherDescription(args); + this.platform.platformMessageHandler.setApplicationSwitcherDescription(description); result.success(null); } catch (err) { Log.e(PlatformMethodCallback.TAG, "setApplicationSwitcherDescription err:" + JSON.stringify(err)); @@ -398,6 +399,12 @@ class PlatformMethodCallback implements MethodCallHandler { } } + private decodeAppSwitcherDescription(encodedDescription: Map): AppSwitcherDescription { + let color: number = encodedDescription.get('color') as number; + let label: string = encodedDescription.get('label') as string; + return new AppSwitcherDescription(color, label); + } + private decodeSystemUiOverlays(encodedSystemUiOverlay: string[]): SystemUiOverlay[] { let overlays: SystemUiOverlay[] = []; for(let i = 0; i < encodedSystemUiOverlay.length; i++) { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index 8b7a13ff5ac742b6bb52de6df043412f80e58443..124eb6488d1a9d8062a3d9133f34564e798cd57d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -129,6 +129,7 @@ export default class FlutterEntry implements Host { onBackPress() { Log.d(TAG, "FlutterEntry onBackPress==="); this?.delegate?.flutterEngine?.getNavigationChannel()?.popRoute(); + this?.delegate?.flutterEngine?.getTextInputChannel()?.textInputMethodHandler?.hide(); } shouldDispatchAppLifecycleState(): boolean { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterCallbackInformation.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterCallbackInformation.ets index 26202727fac9b327d8a4a024667ef30ea067a6e8..7f9111e95f95d9784422a7695dd0db712690763e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterCallbackInformation.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterCallbackInformation.ets @@ -16,9 +16,9 @@ import FlutterNapi from '../embedding/engine/FlutterNapi'; export class FlutterCallbackInformation { - callbackName: string; - callbackClassName: string; - callbackLibraryPath: string; + callbackName?: string; + callbackClassName?: string; + callbackLibraryPath?: string; /** * Get callback information for a given handle. @@ -31,7 +31,13 @@ export class FlutterCallbackInformation { return FlutterNapi.nativeLookupCallbackInformation(handle); } - constructor(callbackName: string, callbackClassName: string, callbackLibraryPath: string) { + constructor(callbackName?: string, callbackClassName?: string, callbackLibraryPath?: string) { + this.callbackName = callbackName; + this.callbackClassName = callbackClassName; + this.callbackLibraryPath = callbackLibraryPath; + } + + init(callbackName: string, callbackClassName: string, callbackLibraryPath: string) { this.callbackName = callbackName; this.callbackClassName = callbackClassName; this.callbackLibraryPath = callbackLibraryPath; diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index 390b300b202a7a2b3c98fd6516deafedfff8f975..473feb562ef2e514295f71ca29a328f405596f71 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -138,7 +138,9 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeDecodeUtf8", flutter::PlatformViewOHOSNapi::nativeDecodeUtf8), - + DECLARE_NAPI_FUNCTION( + "nativeLookupCallbackInformation", + flutter::PlatformViewOHOSNapi::nativeLookupCallbackInformation), }; FML_DLOG(INFO) << "Init NAPI size=" << sizeof(desc) / sizeof(desc[0]); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 9ac9dfafd2b1a88ca92ccf9a6b13e0587581cf92..d46617ef3a738051ec6cfe7fff79c14bea7b4778 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -29,6 +29,7 @@ #include "flutter/shell/platform/ohos/ohos_shell_holder.h" #include "flutter/shell/platform/ohos/surface/ohos_native_window.h" #include "flutter/shell/platform/ohos/types.h" +#include "flutter/lib/ui/plugins/callback_cache.h" #include "unicode/uchar.h" #include "flutter/shell/platform/ohos/ohos_xcomponent_adapter.h" #include "flutter/shell/platform/ohos/ohos_logging.h" @@ -1797,4 +1798,56 @@ napi_value PlatformViewOHOSNapi::nativeDecodeUtf8(napi_env env, napi_callback_in return result; } +napi_value PlatformViewOHOSNapi::nativeLookupCallbackInformation(napi_env env, napi_callback_info info) +{ + napi_value result; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_status ret = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + if (ret != napi_ok) { + LOGE("nativeLookupCallbackInformation napi_get_cb_info error"); + napi_create_int32(env, -1, &result); + return result; + } + + int64_t handle; + bool lossless; + ret = napi_get_value_bigint_int64(env, args[1], &handle, &lossless); + if (ret != napi_ok) { + LOGE("nativeLookupCallbackInformation napi_get_value_int64 error"); + napi_create_int32(env, -1, &result); + return result; + } + + LOGD("nativeLookupCallbackInformation::handle : %{public}ld", handle); + auto cbInfo = flutter::DartCallbackCache::GetCallbackInformation(handle); + if (cbInfo == nullptr) { + LOGE("nativeLookupCallbackInformation DartCallbackCache GetCallbackInformation nullptr"); + napi_create_int32(env, -1, &result); + return result; + } + + napi_ref callbck_napi_obj; + ret = napi_create_reference(env, args[0], 1, &callbck_napi_obj); + if (ret != napi_ok) { + LOGE("nativeLookupCallbackInformation napi_create_reference error"); + napi_create_int32(env, -1, &result); + return result; + } + + napi_value callbackParam[3]; + napi_create_string_utf8(env, cbInfo->name.c_str(), NAPI_AUTO_LENGTH, &callbackParam[0]); + napi_create_string_utf8(env, cbInfo->class_name.c_str(), NAPI_AUTO_LENGTH, &callbackParam[1]); + napi_create_string_utf8(env, cbInfo->library_path.c_str(), NAPI_AUTO_LENGTH, &callbackParam[2]); + + ret = fml::napi::InvokeJsMethod(env, callbck_napi_obj, "init", 3, callbackParam); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeLookupCallbackInformation init fail "; + napi_create_int32(env, -1, &result); + return result; + } + napi_delete_reference(env, callbck_napi_obj); + napi_create_int32(env, 0, &result); + return result; +} } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 2c9cc19fb5e2a536269d3e1119d52211dea15dc3..9ca6b6f90b41da0860243cbcbe67e953b59eddb0 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -208,6 +208,9 @@ class PlatformViewOHOSNapi { static napi_value nativeDecodeUtf8( napi_env env, napi_callback_info info); + static napi_value nativeLookupCallbackInformation( + napi_env env, + napi_callback_info info); private: static napi_env env_;