提交 afd770f7 编写于 作者: E ester.zhou

added samples

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 dd9ef9fb
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
- [CanvasRenderingContext2D](ui-js-components-canvasrenderingcontext2d.md) - [CanvasRenderingContext2D](ui-js-components-canvasrenderingcontext2d.md)
- [Path2D](ui-js-components-path2d.md) - [Path2D](ui-js-components-path2d.md)
- [OffscreenCanvas](ui-js-components-offscreencanvas.md) - [OffscreenCanvas](ui-js-components-offscreencanvas.md)
- [Grid-container Development](ui-js-components-calendar.md) - [Grid-container Development](ui-js-components-grid.md)
- Svg - Svg
- [Basics](ui-js-components-svg-overview.md) - [Basics](ui-js-components-svg-overview.md)
- [Graph Drawing](ui-js-components-svg-graphics.md) - [Graph Drawing](ui-js-components-svg-graphics.md)
......
...@@ -28,6 +28,8 @@ Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower p ...@@ -28,6 +28,8 @@ Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower p
``` ```
/* xxx.css */ /* xxx.css */
.container { .container {
width:100%;
height:100%;
background-color:#F1F3F5; background-color:#F1F3F5;
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
...@@ -110,6 +112,8 @@ Decrease the y-coordinate over a time frame to make the ball bounce back. Gradua ...@@ -110,6 +112,8 @@ Decrease the y-coordinate over a time frame to make the ball bounce back. Gradua
``` ```
/* xxx.css */ /* xxx.css */
.container { .container {
width:100%;
height:100%;
background-color:#F1F3F5; background-color:#F1F3F5;
display: flex; display: flex;
justify-content: center; justify-content: center;
...@@ -304,7 +308,7 @@ Set the rotation center around an element in different transform-origin position ...@@ -304,7 +308,7 @@ Set the rotation center around an element in different transform-origin position
![en-us_image_0000001222807776](figures/en-us_image_0000001222807776.gif) ![en-us_image_0000001222807776](figures/en-us_image_0000001222807776.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**: > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> transform-origin specifies the origin of an element's transformation. If only one value is set, the other value is 50%. If both values are set, the first value indicates the position on the x-axis, and the second value indicates the position on the y-axis. > transform-origin specifies the origin of an element's transformation. If only one value is set, the other value is 50%. If both values are set, the first value indicates the position on the x-axis, and the second value indicates the position on the y-axis.
...@@ -419,7 +423,7 @@ text{ ...@@ -419,7 +423,7 @@ text{
![en-us_image_0000001267887837](figures/en-us_image_0000001267887837.gif) ![en-us_image_0000001267887837](figures/en-us_image_0000001267887837.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**: > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> After the transform attributes are set, the child element changes with the parent element. Value changing of other attributes (such as height and width) of the parent element will not affect the child element. > After the transform attributes are set, the child element changes with the parent element. Value changing of other attributes (such as height and width) of the parent element will not affect the child element.
...@@ -577,9 +581,21 @@ You can set multiple transform attributes at the same time to apply different tr ...@@ -577,9 +581,21 @@ You can set multiple transform attributes at the same time to apply different tr
![en-us_image_0000001223127712](figures/en-us_image_0000001223127712.gif) ![en-us_image_0000001223127712](figures/en-us_image_0000001223127712.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**: > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> 1. When multiple transform attributes are set, the later one overwrites the previous one. To apply multiple transform styles at the same time, use the shorthand notation; that is, write multiple style values in one transform, for example, transform: scale(1) rotate(0) translate(0,0). > - When multiple transform attributes are set, the later one overwrites the previous one. To apply multiple transform styles at the same time, use the shorthand notation; that is, write multiple style values in one transform, for example, transform: scale(1) rotate(0) translate(0,0).
> >
> 2. When using the shorthand notion, **NOTE** that the animation effect varies according to the sequence of the style values. > - When using the shorthand notion, note that the animation effect varies according to the sequence of the style values.
> >
> 3. The style values in the transform attribute used when the animation starts and ends must be in one-to-one mapping. Only the styles that have value mappings are played. > - The style values in the transform attribute used when the animation starts and ends must be in one-to-one mapping. Only the styles that have value mappings are played.
## Samples
The following samples are provided to help you better understand how to develop animations with the **transform** attribute:
- [`JsAnimation`: Animation App (JavaScript)](https://gitee.com/openharmony/app_samples/tree/master/UI/JsAnimation)
- [`JsAnimationStyle`: JS Animation and Custom Font Styles (API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/JsAnimationStyle)
- [`Clock`: Clock (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/common/Clock)
- [Animation Styles (JavaScaript)](https://gitee.com/openharmony/codelabs/tree/master/JSUI/AnimationDemo)
- [Common Image Operations](https://gitee.com/openharmony/codelabs/tree/master/Media/ImageJsDemo)
\ No newline at end of file
...@@ -11,7 +11,7 @@ You can also customize a new component through proper combination of components ...@@ -11,7 +11,7 @@ You can also customize a new component through proper combination of components
Components can be classified into the following types based on their functions. Components can be classified into the following types based on their functions.
| Type | Components | | Type | Components |
| -------- | -------- | | -------- | -------- |
| Container | badge, dialog, div, form, list, list-item, list-item-group, panel, popup, refresh, stack, stepper, stepper-item, swiper, tabs, tab-bar, tab-content | | Container | badge, dialog, div, form, list, list-item, list-item-group, panel, popup, refresh, stack, stepper, stepper-item, swiper, tabs, tab-bar, tab-content |
| Basic | button, chart, divider, image, image-animator, input, label, marquee, menu, option, picker, picker-view, piece, progress, qrcode, rating, richtext, search, select, slider, span, switch, text, textarea, toolbar, toolbar-item, toggle | | Basic | button, chart, divider, image, image-animator, input, label, marquee, menu, option, picker, picker-view, piece, progress, qrcode, rating, richtext, search, select, slider, span, switch, text, textarea, toolbar, toolbar-item, toggle |
...@@ -19,3 +19,17 @@ Components can be classified into the following types based on their functions. ...@@ -19,3 +19,17 @@ Components can be classified into the following types based on their functions.
| Canvas | canvas | | Canvas | canvas |
| Grid | grid-container, grid-row, grid-col | | Grid | grid-container, grid-row, grid-col |
| SVG | svg, rect, circle, ellipse, path, line, polyline, polygon, text, tspan, textPath, animate, animateMotion, animateTransform | | SVG | svg, rect, circle, ellipse, path, line, polyline, polygon, text, tspan, textPath, animate, animateMotion, animateTransform |
## Samples
The following samples are provided to help you better understand how to develop components:
- [`JsPanel`: Content Display Panel (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/JsPanel)
- [`Popup`: JavaScript Bubble (API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/Popup)
- [`RefreshContainer`: Refresh Container (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/RefreshContainer)
- [`JSComponments`: JavaScript Bubble (API 8)](https://gitee.com/openharmony/app_samples/tree/master/UI/JSComponments)
- [`JsUserRegistration`: User Registration (JavaScript, API 8)](https://gitee.com/openharmony/app_samples/tree/master/UI/JsUserRegistration)
- [`ECG`: Heart Rate Detection (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/common/ECG)
- [`Badge`: Badge (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/Badge)
- [Rating (JavaScript)](https://gitee.com/openharmony/codelabs/tree/master/JSUI/RatingApplication)
- [Simple Video Player](https://gitee.com/openharmony/codelabs/tree/master/Media/VideoOpenHarmony)
...@@ -7,16 +7,16 @@ An application generally consist of more than one page. For example, in a music ...@@ -7,16 +7,16 @@ An application generally consist of more than one page. For example, in a music
The page router finds the target page based on the page URI. The following describes how to implement redirection between two pages: The page router finds the target page based on the page URI. The following describes how to implement redirection between two pages:
1. In the “Project“ window of DevEco Studio, choose entry > src > mainjsdefault. Right-click the pages folder and choose NewJS Page from the shortcut menu to create the detail page. 1. In the **Project** window of DevEco Studio, choose **entry** > **src** > **mainjsdefault**. Right-click the **pages** folder and choose **NewJS Page** from the shortcut menu to create the detail page.
2. Call router.push() to navigate users to the detail page. 2. Call **router.push()** to navigate users to the detail page.
3. Call router.back() to navigate users to the index page. 3. Call **router.back()** to navigate users to the index page.
## Building the Page Layout ## Building the Page Layout
The index and detail pages each contains a &lt;text> component that specifies the current page, and a &lt;button&gt; component that implements the switching between two pages. Example code in .hml files is as follows: The index and detail pages each contains a &lt;text> component that specifies the current page, and a **\<button>** component that implements the switching between two pages. Example code in .hml files is as follows:
``` ```
...@@ -39,7 +39,7 @@ The index and detail pages each contains a &lt;text> component that specifies th ...@@ -39,7 +39,7 @@ The index and detail pages each contains a &lt;text> component that specifies th
## Setting Page Styles ## Setting Page Styles
Set styles for the index and detail pages. Center the &lt;text&gt; and &lt;button&gt; components and space the two components with 50 pixels. The CSS code for the two pages is as follows: Set styles for the index and detail pages. Center the **\<text>** and **\<button>** components and space the two components with 50 pixels. The CSS code for the two pages is as follows:
``` ```
...@@ -60,7 +60,7 @@ Set styles for the index and detail pages. Center the &lt;text&gt; and &lt;butto ...@@ -60,7 +60,7 @@ Set styles for the index and detail pages. Center the &lt;text&gt; and &lt;butto
## Implementing Redirection ## Implementing Redirection
To make the launch method of the &lt;button&gt; component take effect, the redirection logic needs to be implemented in the .js file of the page. Call router.push() to add the page URI to the route stack, that is, to jump to the page specified by the URI. You need to import the router module before calling the router method. The sample code is as follows: To make the launch method of the **\<button>** component take effect, the redirection logic needs to be implemented in the .js file of the page. Call router.push() to add the page URI to the route stack, that is, to jump to the page specified by the URI. You need to import the router module before calling the router method. The sample code is as follows:
``` ```
...@@ -88,6 +88,10 @@ export default { ...@@ -88,6 +88,10 @@ export default {
The figure below shows the effect. The figure below shows the effect.
figure1 Page routing
![en-us_image_0000001222967784](figures/en-us_image_0000001222967784.png) ![en-us_image_0000001222967784](figures/en-us_image_0000001222967784.png)
## Samples
The following sample is provided to help you better understand how to develop page routing:
[`JsRouter`: Page Routing (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/JsRouter)
\ No newline at end of file
...@@ -24,7 +24,7 @@ Create a **&lt;tabs&gt;** component in the .hml file under **pages/index**. ...@@ -24,7 +24,7 @@ Create a **&lt;tabs&gt;** component in the .hml file under **pages/index**.
<text>content2</text> <text>content2</text>
</div> </div>
</tab-content> </tab-content>
</tabs> </tabs>
</div> </div>
``` ```
...@@ -165,7 +165,7 @@ Add the **change** event for the **&lt;tabs&gt;** component to display the index ...@@ -165,7 +165,7 @@ Add the **change** event for the **&lt;tabs&gt;** component to display the index
``` ```
<!-- index.hml --> <!-- index.hml -->
<div class="container" style="background-color:#F1F3F5;"> <div class="container" style="background-color:#F1F3F5;">
<tabs class="tabs"onchange="tabChange"> <tabs class="tabs" onchange="tabChange">
<tab-bar class="tabBar"> <tab-bar class="tabBar">
<text class="tabBarItem">item1</text> <text class="tabBarItem">item1</text>
<text class="tabBarItem">item2</text> <text class="tabBarItem">item2</text>
...@@ -324,6 +324,6 @@ export default { ...@@ -324,6 +324,6 @@ export default {
## Samples ## Samples
The following sample is provided to help you better understand how to develop the **&lt;tabs&gt;** component: The following sample is provided to help you better understand how to develop the **&lt;tabs&gt;** component:
[`Tabs`: Tabs (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/Tabs) [`Tabs`: Tabs (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/Tabs)
\ No newline at end of file
...@@ -32,7 +32,7 @@ canvas{ ...@@ -32,7 +32,7 @@ canvas{
![en-us_image_0000001232162316](figures/en-us_image_0000001232162316.png) ![en-us_image_0000001232162316](figures/en-us_image_0000001232162316.png)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> - The default background color of the **&lt;canvas&gt;** component is the same as that of the parent component. > - The default background color of the **&lt;canvas&gt;** component is the same as that of the parent component.
> >
> - The default width and height of **&lt;canvas&gt;** are 300 px and 150 px, respectively. > - The default width and height of **&lt;canvas&gt;** are 300 px and 150 px, respectively.
...@@ -86,9 +86,29 @@ Add the long press event to the **&lt;canvas&gt;** component. When the event is ...@@ -86,9 +86,29 @@ Add the long press event to the **&lt;canvas&gt;** component. When the event is
``` ```
/* xxx.css */.container{ flex-direction: column; justify-content: center; align-items: center; background-color: #F1F3F5;}canvas{ width: 500px; height: 500px; background-color: #fdfdfd; border: 5px solid red; /* xxx.css */
.container{
width:100%;
height:100%;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #F1F3F5;
}
canvas{
width: 500px;
height: 500px;
background-color: #fdfdfd;
border: 5px solid red;
margin-bottom: 50px; margin-bottom: 50px;
}.content{ border: 5px solid blue; padding: 10px; width: 90%; height: 400px; overflow: scroll;} }
.content{
border: 5px solid blue;
padding: 10px;
width: 90%;
height: 400px;
overflow: scroll;
}
``` ```
...@@ -107,15 +127,22 @@ export default { ...@@ -107,15 +127,22 @@ export default {
ctx.strokeRect(100,100,300,300); ctx.strokeRect(100,100,300,300);
}, },
getUrl(){ getUrl(){
let el = this.$refs.canvas1; let el = this.$refs.canvas1
let dataUrl = el.toDataURL(); let dataUrl = el.toDataURL()
this.dataURL = dataUrl; this.dataURL = dataUrl;
prompt.showToast({duration:2000,message:"long press,get dataURL"}); prompt.showToast({duration:2000,message:"long press,get dataURL"})
} }
} }
``` ```
![en-us_image_0000001276003513](figures/en-us_image_0000001276003513.gif) ![en-us_image_0000001276003513](figures/en-us_image_0000001276003513.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> The **&lt;canvas&gt;** component cannot be created in **onInit** or **onReady**. > The **&lt;canvas&gt;** component cannot be created in **onInit** or **onReady**.
## Samples
The following sample is provided to help you better understand how to develop the **\<canvas>** component:
[`JsCanvas`: \<canvas> (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/JsCanvas)
...@@ -217,9 +217,8 @@ export default { ...@@ -217,9 +217,8 @@ export default {
![en-us_image_0000001275803181](figures/en-us_image_0000001275803181.gif) ![en-us_image_0000001275803181](figures/en-us_image_0000001275803181.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>The **&lt;chart&gt;** component does not display the value of each point.
> >
> The **&lt;chart&gt;** component does not display the value of each point.
## Setting the Chart Attributes ## Setting the Chart Attributes
...@@ -305,7 +304,7 @@ export default { ...@@ -305,7 +304,7 @@ export default {
} }
``` ```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> - The **options** attribute supports the settings of bar charts and line charts but does not support those of gauge charts. > - The **options** attribute supports the settings of bar charts and line charts but does not support those of gauge charts.
> >
> - The **datasets** attribute supports the datasets for bar charts and line charts but does not support those of gauge charts. > - The **datasets** attribute supports the datasets for bar charts and line charts but does not support those of gauge charts.
...@@ -400,12 +399,7 @@ export default { ...@@ -400,12 +399,7 @@ export default {
} }
}, },
}, },
addData() { addData() { this.$refs.linechart.append({ serial: 0, data: [Math.floor(Math.random() * 400) + 200] }) }
this.$refs.linechart.append({
serial: 0,
data: [Math.floor(Math.random() * 400) + 200]
})
}
} }
``` ```
...@@ -624,6 +618,6 @@ export default { ...@@ -624,6 +618,6 @@ export default {
![en-us_image_0000001232162328](figures/en-us_image_0000001232162328.gif) ![en-us_image_0000001232162328](figures/en-us_image_0000001232162328.gif)
## Samples ## Samples
The following sample is provided to help you better understand how to develop the **&lt;chart&gt;** component: The following sample is provided to help you better understand how to develop the **&lt;chart&gt;** component:
[`Chart`: chart (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/chart) [`Chart`: chart (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/chart)
\ No newline at end of file
...@@ -152,7 +152,7 @@ export default { ...@@ -152,7 +152,7 @@ export default {
![en-us_image_0000001223287720](figures/en-us_image_0000001223287720.gif) ![en-us_image_0000001223287720](figures/en-us_image_0000001223287720.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> - This component supports only one child component. > - This component supports only one child component.
> >
> - Attributes and styles of a **&lt;dialog&gt;** component cannot be dynamically updated. > - Attributes and styles of a **&lt;dialog&gt;** component cannot be dynamically updated.
......
...@@ -242,3 +242,9 @@ export default { ...@@ -242,3 +242,9 @@ export default {
![en-us_image_0000001276003501](figures/en-us_image_0000001276003501.gif) ![en-us_image_0000001276003501](figures/en-us_image_0000001276003501.gif)
## Samples
The following sample is provided to help you better understand how to develop the **\<grid>** component:
[`JsGrid`: grid (JavaScript, API 7)](https://gitee.com/openharmony/app_samples/tree/master/UI/JsGrid)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册