Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ohos]适配最新的PlatformView方案 #2049

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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