diff --git a/shell/platform/ohos/flutter_embedding/.gitignore b/shell/platform/ohos/flutter_embedding/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4510e76666c8541e4a1195a0ed2850754c9fc243 --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/.gitignore @@ -0,0 +1,10 @@ +/node_modules +/oh_modules +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets index 9415d242aab114f2f916945d31bd870c5007c6e2..114387d16e7a585188aedb535fa62b8671d7a7b7 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/loader/FlutterLoader.ets @@ -134,7 +134,6 @@ export default class FlutterLoader { if (shellArgs == null) { shellArgs = new Array(); } - // shellArgs.push("--icu-symbol-prefix=_binary_icudtl_dat"); shellArgs.push( "--icu-native-lib-path=" + this.flutterApplicationInfo.nativeLibraryDir @@ -177,7 +176,7 @@ export default class FlutterLoader { shellArgs.push("--leak-vm=" + true); - shellArgs.push("--enable-impeller"); + //shellArgs.push("--enable-impeller"); // //最终初始化操作 const costTime = Date.now() - this.initStartTimestampMillis; @@ -217,4 +216,4 @@ class InitResult { this.engineCachesPath = engineCachesPath; this.dataDirPath = dataDirPath; } -} \ No newline at end of file +} diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets index 7ca54bce7c98b55549de5285a3fe05bf88318cf3..cd717faa545f88a6378655ddcfd9607fd898f2c7 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets @@ -112,7 +112,6 @@ export default class PlatformViewsChannel { direction = Direction.Rtl; } - Log.i(TAG, "Enter create " + usesPlatformViewLayer + " " + createArgs.get("direction") + createArgs.get("viewType")); try { if (usesPlatformViewLayer) { const request: PlatformViewCreationRequest = new PlatformViewCreationRequest( @@ -144,6 +143,15 @@ export default class PlatformViewsChannel { additionalParams, displayMode ); + + Log.i(TAG, `Create texture param id:${request.viewId}, + type:${request.viewType}, + w:${request.logicalWidth}, + h:${request.logicalHeight}, + l:${request.logicalLeft}, + t:${request.logicalTop}, + d:${request.direction}`); + const textureId = this.handler.createForTextureLayer(request); if (textureId == PlatformViewsHandler.NON_TEXTURE_FALLBACK) { if (!hybridFallback) { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/RestorationChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/RestorationChannel.ets index 9c486edd88568dc3a56aac4d6fc1eca6447fbf89..2d4440cdbb52465a6d1c1e4469f6b19a1de6d99e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/RestorationChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/RestorationChannel.ets @@ -58,7 +58,7 @@ export default class RestorationChannel { // Holds the most current restoration data which may have been provided by the engine // via "setRestorationData" or by the framework via the method channel. This is the data the // framework should be restored to in case the app is terminated. - private restorationData: Int8Array; + private restorationData: Uint8Array; private channel: MethodChannel; private pendingFrameworkRestorationChannelRequest: MethodResult; private engineHasProvidedData: boolean = false; @@ -75,12 +75,12 @@ export default class RestorationChannel { } /** Obtain the most current restoration data that the framework has provided. */ - getRestorationData(): Int8Array { + getRestorationData(): Uint8Array { return this.restorationData; } /** Set the restoration data from which the framework will restore its state. */ - setRestorationData(data: Int8Array) { + setRestorationData(data: Uint8Array) { this.engineHasProvidedData = true; if (this.pendingFrameworkRestorationChannelRequest != null) { // If their is a pending request from the framework, answer it. @@ -154,7 +154,7 @@ export default class RestorationChannel { } }; - private packageData(data: Int8Array): Map { + private packageData(data: Uint8Array): Map { const packaged: Map = new Map(); packaged.set("enabled", true); packaged.set("data", data); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets index 5c80c6c580951e631a834ea243869a04e38edf79..266884717d502e23f840c40e631f8d63f0d09e11 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/TextInputChannel.ets @@ -49,18 +49,42 @@ export default class TextInputChannel { break; case "TextInput.setClient": const textInputClientId: number = args[0] as number; + //TODO: parse configuration const config: Configuration = null; this.textInputMethodHandler.setClient(textInputClientId, config); result.success(null); break; case "TextInput.requestAutofill": + //TODO: requestAutofill + result.notImplemented(); + break; case "TextInput.setPlatformViewClient": + //TODO: + result.notImplemented(); + break; case "TextInput.setEditingState": this.textInputMethodHandler.setEditingState(TextEditState.fromJson(args)); + result.success(null); + break; case "TextInput.setEditableSizeAndTransform": + //TODO: + result.notImplemented(); + break; case "TextInput.clearClient": + this.textInputMethodHandler.clearClient(); + result.success(null); + break; case "TextInput.sendAppPrivateCommand": + //TODO: + result.notImplemented(); + break; case "TextInput.finishAutofillContext": + //TODO: + result.notImplemented(); + break; + default: + result.notImplemented(); + break; } } }); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets index 57944bd721a3cfb05d1683ed2d07267cabd67d1b..5e29d78d0a4872654cdd3d1781f7ce51a9464471 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityDelegate.ets @@ -37,6 +37,8 @@ import Settings from './Settings'; const TAG = "FlutterAbilityDelegate"; const PLUGINS_RESTORATION_BUNDLE_KEY = "plugins"; +const FRAMEWORK_RESTORATION_BUNDLE_KEY = "framework"; + /** * 主要职责: * 1、初始化engine @@ -130,7 +132,10 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { * @param want */ onRestoreInstanceState(want: Want) { - + let frameworkState: Uint8Array = want.parameters[FRAMEWORK_RESTORATION_BUNDLE_KEY] as Uint8Array; + if (this.host.shouldRestoreAndSaveState()) { + this.flutterEngine.getRestorationChannel().setRestorationData(frameworkState ?? null); + } } /** @@ -254,11 +259,11 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { } onWindowStageCreate() { + this.ensureAlive(); + this.doInitialFlutterViewRun(); if (this.shouldDispatchAppLifecycleState()) { this.flutterEngine.getLifecycleChannel().appIsResumed(); } - this.ensureAlive(); - this.doInitialFlutterViewRun(); } onWindowStageDestroy() { @@ -351,6 +356,9 @@ class FlutterAbilityDelegate implements ExclusiveAppComponent { onSaveState(reason: AbilityConstant.StateType, wantParam: { [key: string]: Object; }): AbilityConstant.OnSaveResult { Log.i(TAG, "onSaveInstanceState. Giving framework and plugins an opportunity to save state."); this.ensureAlive(); + if (this.host.shouldRestoreAndSaveState()) { + wantParam[FRAMEWORK_RESTORATION_BUNDLE_KEY] = this.flutterEngine.getRestorationChannel().getRestorationData(); + } if (this.host.shouldAttachEngineToActivity()) { const plugins = {} const result = this.flutterEngine.getAbilityControlSurface().onSaveState(reason, plugins); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets index 826408b9a5476ee365d1604b6f54837f1d0f1c8f..fd835762802d6dc9003da529ffd91cccde64e062 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/PlatformPlugin.ets @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import PlatformChannel, { AppSwitcherDescription, Brightness, diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets index 87c91df70bf51b5135403710ab7ce3bd6616428f..aa44a4958e67eb04dd5255d76f524f8c7aca1749 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/BinaryMessenger.ets @@ -87,7 +87,6 @@ export interface BinaryMessageHandler { * @see EventChannel , which supports communication using event streams. */ export abstract class BinaryMessenger { - //makeBackgroundTaskQueue() makeBackgroundTaskQueue(options?: TaskQueueOptions): TaskQueue { throw new Error("makeBackgroundTaskQueue not implemented.") } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets index 78fcd30defbf81b3dca2db930babb9b1957a7c9a..60de27310cbd87395530d58979e1c60236735a5d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodCall.ets @@ -51,7 +51,7 @@ export default class MethodCall { } else if (arguments instanceof Map) { return (this.args as Map).has(key); } else if (ToolUtils.isObj(this.args)) { - return this.args.hasOwnProperty(key); + return Object.prototype.hasOwnProperty.call(this.args, key); } else { throw new Error("ClassCastException"); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets index e6ae8800e74a7ce3f21a381289b93ed493ac6998..5a7de31d1dea2f872f6c20330d90ca91a71ecfa9 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/common/MethodChannel.ets @@ -204,6 +204,7 @@ class IncomingMethodCallHandler implements BinaryMessageHandler { }, notImplemented: (): void => { + Log.w(MethodChannel.TAG,"method not implemented"); reply.reply(null); } }); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 33d5cda317dbf2e6d952f452b61244949d5083f0..f837940fa13a309b3d6a2ddadadb9ca821daaf27 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -91,7 +91,7 @@ export default class TextInputPlugin implements EditingStateWatcher{ if(this.imcFlag != true) { this.listenKeyBoardEvent(); } - this.inputMethodController.showSoftKeyboard().then(()=> { + this.inputMethodController.showTextInput().then(()=> { Log.d(TextInputPlugin.TAG, "Succeeded in showing softKeyboard"); }).catch((err) => { Log.e(TextInputPlugin.TAG, "Failed to show softKeyboard:" + JSON.stringify(err)); @@ -99,7 +99,7 @@ export default class TextInputPlugin implements EditingStateWatcher{ } private async hideTextInput(): Promise { - this.inputMethodController.hideSoftKeyboard().then(() => { + this.inputMethodController.hideTextInput().then(() => { Log.d(TextInputPlugin.TAG, "Succeeded in hide softKeyboard"); }).catch((err) => { Log.e(TextInputPlugin.TAG, "Failed to hide softKeyboard:" + JSON.stringify(err)); diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewWrapper.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewWrapper.ets index e49d0fd33a6c046d7cbe6242388f7e4816ed5ed1..5bd02dcc81e2d652aa16d9865b95a4dec5740d3e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewWrapper.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewWrapper.ets @@ -55,8 +55,6 @@ export class PlatformViewWrapper { { compType: "Column", children: [], - attributes: {backgroundColor: Color.Red}, - events: {onTouch : this.onTouch} } ); @@ -79,6 +77,14 @@ export class PlatformViewWrapper { this.model.params['marginTop'] = parameters['marginTop']; this.left = parameters['marginLeft']; this.top = parameters['marginTop']; + + if (parameters.hasOwnProperty('width')) { + this.model.params['width'] = parameters['width']; + } + + if (parameters.hasOwnProperty('height')) { + this.model.params['height'] = parameters['height']; + } } public addDvModel(model: DVModel): void { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 9d8fa2dcb428f01a8d71ba70298a17bef5cf33c9..5838afd27f0068e519588135222e504b30fc1699 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -159,6 +159,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili embeddedViewLayoutParams["height"] = physicalHeight; } } + + onComplete.run(new PlatformViewBufferSize(request.newLogicalWidth, request.newLogicalHeight)); } offset(viewId: number, top: number, left: number): void { diff --git a/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 b/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 index d550d9bb1cc9e8d0c1187c9de1bd4b674d9da24b..52c0a40dd28d8df5b24e7a8bcac7d20d397f9740 100755 --- a/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 +++ b/shell/platform/ohos/flutter_embedding/hvigor/hvigor-config.json5 @@ -14,8 +14,8 @@ */ { - "hvigorVersion": "2.4.2", + "hvigorVersion": "2.1.1", "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.4.2" + "@ohos/hvigor-ohos-plugin": "2.1.1" } }