# scene **Repository Path**: chinasoft4_ohos/scene ## Basic Information - **Project Name**: scene - **Description**: scene是一个基于Component的轻量级导航和页面切分组件库 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-06-17 - **Last Updated**: 2021-08-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # scene ## 项目介绍 - 项目名称:scene - 所属系列:openharmony的第三方组件适配移植 - 功能:基于Component的轻量级导航和页面切分组件库 - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio2.2 Beta1 - 基线版本:Release v1.2.0 ## 效果演示 ## 安装教程 1.在项目根目录下的build.gradle文件中添加。 ``` allprojects { repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } } } ``` 2.在entry模块的build.gradle文件中 ``` dependencies { implementation('com.gitee.chinasoft_ohos:scene:0.0.3-SNAPSHOT') implementation('com.gitee.chinasoft_ohos:scene-navigation:0.0.3-SNAPSHOT') implementation('com.gitee.chinasoft_ohos:scene-dialog:0.0.3-SNAPSHOT') implementation('com.gitee.chinasoft_ohos:scene-ktx:0.0.3-SNAPSHOT') implementation('com.gitee.chinasoft_ohos:scene-shared-element-animation:0.0.3-SNAPSHOT') implementation('com.gitee.chinasoft_ohos:scene-ui:0.0.3-SNAPSHOT') ...... } ``` 在sdk6,DevEco Studio2.2 Beta1下项目可直接运行。如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 ## 使用说明 Scene有2个子类:NavigationScene和GroupScene,其中: * 1.NavigationScene支持页面切换 * 2.GroupScene支持页面切分 | Scene | NavigationScene |GroupScene | |---|---|---| |||| 简单的接入,让主Ability继承于SceneAbility即可: ```java public class MainAbility extends SceneAbility { @Override protected Class getHomeSceneClass() { return MainScene.class; } @Override protected boolean supportRestore() { return false; } } ``` 一个简单的Scene示例: ```java public class SwipeBackDemo extends AppCompatScene { private boolean mSwipeBack = false; @Override protected Component onCreateContentView(LayoutScatter inflater, ComponentContainer container, Intent savedInstanceState) { Component component = inflater.parse(ResourceTable.Layout_swipe_back_demo, container, false); setTitle(""); return component; } @Override public void onAbilityCreated(Intent savedInstanceState) { super.onAbilityCreated(savedInstanceState); setSwipeEnabled(true); } } public class DialogSamples extends Scene { @Override public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) { Component component = scatter.parse(ResourceTable.Layout_dialog_sample, container, false); initComment(component); return component; } @Override public void onViewCreated(Component component, Intent intent) { initComment(component); super.onViewCreated(component, intent); } } ``` 一个新的App可以通过直接继承SceneAbility的方式接入Scene, 但如果已有的Ability不方便更改继承关系,则可参考SceneAbility的代码直接使用SceneDelegate来处理, 以西瓜视频的首页迁移方案为例: 首先在首页的XML申明一个存放Scene的布局:scene_container ```xml ``` 再创建一个透明的Scene作为根Scene ```java public static class EmptyHolderScene extends Scene { /** * EmptyHolderScene */ public EmptyHolderScene() { } @Override public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) { return new Component(container.getContext()); } @Override public void onViewCreated(Component component, Intent intent) { super.onViewCreated(component, intent); ShapeElement shapeElement = new ShapeElement(); shapeElement.setRgbColor(new RgbColor(Color.TRANSPARENT.getValue())); getView().setBackground(shapeElement); } } ``` 绑定这个透明的Scene到 R.id.scene_container ```java mSceneAbilityDelegate = NavigationSceneUtility.setupWithAbility(this, EmptyHolderScene.class) .toView(ResourceTable.Id_scene_container).drawWindowBackground(false) .fixSceneWindowBackgroundEnabled(true) .sceneBackground(Color.WHITE.getValue()) .supportRestore(false) .build(); ``` 实质上是有个透明的Scene盖在首页,但是视觉上看不出来 然后在Ability中提供Push的方法 ```java public void push(Class clazz, IntentParams argument) { push(clazz, argument, new PushOptions.Builder().build()); } ``` 这样就基本迁移完成,可以在这个Ability中直接打开新的Scene页面了。 ## 测试信息 CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与原组件基本无差异 ## 版本迭代 - 0.0.3-SNAPSHOT ## 版权和许可信息 ``` Copyright (c) 2019 ByteDance Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```