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]默认显式使用surface模式 #2023

Merged
merged 1 commit into from
Apr 23, 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 @@ -6,6 +6,7 @@
5. [ohos]使用Navigation,解决半透明弹窗不透底的问题
6. [ohos]修复使用Navigation后页面后退异常的问题
7. [ohos]代码重构,便于后续优化
8. [ohos]默认显式使用surface模式

## 4.5.4
1. [ohos]支持传入启动参数和dart入口参数
Expand Down
18 changes: 8 additions & 10 deletions example/ohos/entry/src/main/ets/entryability/EntryAbility.ets
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import Want from '@ohos.app.ability.Want';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import window from '@ohos.window';
import hilog from '@ohos.hilog';
import {
FlutterBoost,
FlutterBoostDelegate,
FlutterBoostRouteOptions,
FlutterBoostSetupOptionsBuilder
} from '@ohos/flutter_boost';
import FlutterManager from '@ohos/flutter_ohos/src/main/ets/embedding/ohos/FlutterManager';

import { FlutterManager} from '@ohos/flutter_ohos';
import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant';
import { RouterModule, RouterOptions } from '../router/RouterModule';
import { RouterNameConstants } from '../constants/RouterConstants';

Expand Down Expand Up @@ -66,8 +65,8 @@ export default class EntryAbility extends UIAbility implements FlutterBoostDeleg
FlutterManager.getInstance().popUIAbility(this)
}

// Main window is created, set main page for this ability
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate');
FlutterManager.getInstance().pushWindowStage(this, windowStage)

Expand All @@ -88,23 +87,22 @@ export default class EntryAbility extends UIAbility implements FlutterBoostDeleg
}
hilog.info(0x0000, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});

}, optionsBuilder.build())
}

// Main window is destroyed, release UI related resources
onWindowStageDestroy(): void {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy');
FlutterManager.getInstance().popWindowStage(this)
}

// Ability has brought to foreground
onForeground(): void {
// Ability has brought to foreground
hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground');
}

// Ability has back to background
onBackground(): void {
// Ability has back to background
hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground');
}
}
10 changes: 8 additions & 2 deletions example/ohos/entry/src/main/ets/pages/FlutterUIComponent.ets
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const TAG: string = "FlutterUIComponent";
export struct FlutterUIComponent {
@Prop uri: string;
@Prop params: Record<string, Object>;
@Prop xComponentType: XComponentType = XComponentType.SURFACE;

private flutterEntry: FlutterBoostEntry | null = null;
private flutterView?: FlutterView;
Expand All @@ -16,13 +17,15 @@ export struct FlutterUIComponent {
.combine(TransitionEffect.move(TransitionEdge.END)).animation({curve: Curves.springMotion()});

aboutToAppear() {
hilog.info(0x0000, TAG, 'Component(#%{public}s) aboutToAppear===', this.uri);
this.flutterEntry = new FlutterBoostEntry(getContext(this), {
uri: this.uri,
params: this.params,
});
this.flutterEntry.aboutToAppear();
// The |aboutToAppear| method is called first,
// followed by the |getFlutterView| method.
this.flutterView = this.flutterEntry.getFlutterView();
hilog.info(0x0000, TAG, 'Component(#%{public}s) aboutToAppear===', this.uri);
}

aboutToDisappear() {
Expand All @@ -42,7 +45,10 @@ export struct FlutterUIComponent {

build() {
Stack() {
FlutterPage({ viewId: this.flutterView?.getId() })
FlutterPage({
viewId: this.flutterView?.getId(),
xComponentType: this.xComponentType
})
}
.onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => {
if (isVisible) {
Expand Down
9 changes: 7 additions & 2 deletions example/ohos/entry/src/main/ets/pages/FlutterUIDialog.ets
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ const TAG: string = "FlutterUIDialog";
export struct FlutterUIDialog {
private flutterEntry: FlutterBoostEntry | null = null;
private flutterView: FlutterView | null = null;
@Prop xComponentType: XComponentType = XComponentType.SURFACE;

aboutToAppear() {
hilog.info(0x0000, TAG, "aboutToAppear===");
this.flutterEntry = new FlutterBoostEntry(getContext(this));
this.flutterEntry.aboutToAppear();

// The |aboutToAppear| method is called first,
// followed by the |getFlutterView| method.
this.flutterView = this.flutterEntry.getFlutterView();
}

Expand All @@ -48,7 +50,10 @@ export struct FlutterUIDialog {

build() {
NavDestination() {
FlutterPage({ viewId: this.flutterView!.getId() })
FlutterPage({
viewId: this.flutterView!.getId(),
xComponentType: this.xComponentType
})
}
.mode(NavDestinationMode.DIALOG)
.hideTitleBar(true)
Expand Down
8 changes: 7 additions & 1 deletion example/ohos/entry/src/main/ets/pages/FlutterUIPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ const TAG: string = "FlutterUIPage";
export struct FlutterUIPage {
private flutterEntry: FlutterBoostEntry | null = null;
private flutterView: FlutterView | null = null;
@Prop xComponentType: XComponentType = XComponentType.SURFACE;

aboutToAppear() {
hilog.info(0x0000, TAG, "aboutToAppear===");
this.flutterEntry = new FlutterBoostEntry(getContext(this));
this.flutterEntry.aboutToAppear();
// The |aboutToAppear| method is called first,
// followed by the |getFlutterView| method.
this.flutterView = this.flutterEntry.getFlutterView();
}

Expand All @@ -47,7 +50,10 @@ export struct FlutterUIPage {

build() {
NavDestination() {
FlutterPage({ viewId: this.flutterView!.getId() })
FlutterPage({
viewId: this.flutterView!.getId(),
xComponentType: this.xComponentType
})
}
.hideTitleBar(true)
.onBackPressed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class FlutterBoostPlugin implements FlutterPlugin, MethodCallHandler, Nat
}

onPushFlutterRoute(params: CommonParams) {
Log.i(TAG, "#onPushFlutterRoute: " + params.pageName);
if (this.delegate) {
const builder = new FlutterBoostRouteOptionsBuilder()
if (params.pageName) {
Expand Down Expand Up @@ -228,15 +229,16 @@ export class FlutterBoostPlugin implements FlutterPlugin, MethodCallHandler, Nat
* 向Flutter侧发送pushRoute事件
* */
public pushRoute(uniqueId: string, pageName: string, args: Record<string, Object>, callback: () => void) {
Log.i(TAG, "#pushRoute start: " + uniqueId + ", " + pageName);
Log.i(TAG, "#pushRoute start: " + pageName);
const timestamp = (new Date()).getTime();
if (this.channel) {
this.checkEngineState();
let params = new CommonParams()
params.uniqueId = uniqueId
params.pageName = pageName
params.arguments = args
this.channel.pushRoute(params, () => {
Log.i(TAG, "#pushRoute end: " + uniqueId + ", " + pageName);
Log.i(TAG, "#pushRoute end: " + pageName + ", cost: " + ((new Date()).getTime()-timestamp) + "ms.");
if (callback) {
callback();
}
Expand Down