Skip to content

Commit

Permalink
[ohos]适配最新的PlatformView方案
Browse files Browse the repository at this point in the history
  • Loading branch information
0xZOne committed Jun 7, 2024
1 parent 488ecd4 commit 18a195c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
1. [dart]添加`SystemChrome.setPreferredOrientations`测试案例
2. [ohos]修复透明弹窗由于被其他全屏page遮盖导致弹窗再现时页面假死等一系列问题,补充和dialog相关场景example demo
3. [ohos]解决FlutterBoostEntry中onPageHide的调用和onPageShow不对称问题
4. [ohos]适配最新的PlatformView方案

# 4.5.10
1. [dart]添加HDR/HEIC/HEIF/TIFF/WBMP/WEBP等图片格式的测试案例
Expand Down
70 changes: 34 additions & 36 deletions example/ohos/entry/src/main/ets/platform_view/SimpleTextView.ets
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
import common from '@ohos.app.ability.common';
import PlatformView from '@ohos/flutter_ohos/src/main/ets/plugin/platform/PlatformView';
import { DVModel } from '@ohos/flutter_ohos/src/main/ets/view/DynamicView/dynamicView';
import { createDVModelFromJson } from '@ohos/flutter_ohos/src/main/ets/view/DynamicView/dynamicViewJson';
import PlatformView, { Params } from '@ohos/flutter_ohos/src/main/ets/plugin/platform/PlatformView';

@Component
struct TextComponent {
@Prop params: Params
embededView: SimpleTextView = this.params.platformView as SimpleTextView

build() {
Column() {
Text(`PlatformView: #${this.embededView.getViewId()}`)
.fontSize(18)
Text("Hi, there! I'm from ArkUI.")
.fontColor('#0D9FFB')
.fontSize(18)
.margin(18)
}
.alignItems(HorizontalAlign.Center)
.justifyContent(FlexAlign.Center)
.direction(Direction.Ltr)
.width('100%')
.height('100%')
}
}

@Builder
function TextBuilder(params: Params) {
TextComponent({ params: params })
.backgroundColor('#F1F3F5')
}

@Observed
export class SimpleTextView extends PlatformView {
private viewId: number;
private model: DVModel;

constructor(context: common.Context, viewId: number, args: ESObject) {
super()
this.viewId = viewId;
this.model = this.createDVModel();
}

private createDVModel(): DVModel {
return createDVModelFromJson(
{
compType: "Column",
attributes: {
backgroundColor: '#F1F3F5',
height: '100%',
width: '100%'
},
children: [
{
compType: "Text",
attributes: {
value: "PlatformView: #" + this.viewId.toString(),
fontSize: 18,
},
},
{
compType: "Text",
attributes: {
value: "Hi, there! I'm from ArkUI.",
fontColor: '#0D9FFB',
fontSize: 18,
marginTop: 20,
},
}
],
}
);
getView(): WrappedBuilder<[Params]> {
return new WrappedBuilder(TextBuilder);
}

getView(): DVModel {
return this.model;
getViewId(): number {
return this.viewId;
}

dispose(): void {
Expand Down

0 comments on commit 18a195c

Please sign in to comment.