I. BACKGROUND
After sharing a quick application with a small partner (hereafter referred to as HAP), there are many pending ideas that have not been tried. This week there is time to simply develop a popular microblogging application, mainly related to the difficulties: Rich text, long lists, galleries. Here will be the whole development process encountered problems and solutions to share the ideas and methods to everyone, hoping to step on the pit of you have some help.
Code: Https://github.com/SmileSmith/quickapp-weibo
PS: Fast application seems to have not released the official version, the middle will contain some spit groove (scarlet Letter), Welcome to guide and shoot bricks ~
Ii. development issues and difficulties records 1. Preparation
Note The version number of Toolkit and packager in Package.json, which indicates the version of HAP Engineering Toolkit, is recommended to perform HAP update--force update to the latest version, which supports more features.
"Toolkit": "0.0.30","packager": "0.0.5"
For example, in the "original" Fast app Quickapp--helloworld experience, this version or 0.0.26,babel does not support Stage2. Currently 0.0. Version 30 has been supported by default.
Performing HAP update--force will cause. BABELRC and. Eslintrc.json to be refreshed, please note.
2. Directory structure
Due to previous project habits, do not like to directly put the page folder under SRC, instead of unified under the Src/pages, in Mainfest.json modified as follows
"Router" : { "entry": "Pages/home" , "p Ages ": {" pages/home ": {//plus pages/ " component ":" Index "}, ...}, " disp Lay ": {" Titlebarbackgroundcolor ":" #e6162d " "Titlebartextcolor": "#eeeeee" "menu": True "pages" : { "Pages/home" : {//plus pages/ "Titlebartext": Home "menu": false }, ...
3, internal interface package
The internal interface involves asynchronous operations, most of which are implemented using success, fail callbacks, as in the case of small programs. To facilitate subsequent development, the internal interface is simply encapsulated with promise and the interface name is maintained in accordance with the applet. The $app is then globally imported in App.ux.
This way, there is no need to write the import router from ' @system. Router ' in each page; or var router = require ("@system. Router"), use this. $app. API () directly.
See Src/utils/mv.js and Src/utils/app.ux for details.
4. long list using internal components list
Please refer to the official list tutorial for instructions, note the following performance tuning recommendations, highlighting the points here:
1, list through, the different structure of the list elements set different type, the elements of the list set a unique tid, to achieve the DOM structure reuse, improve the performance of sliding and rendering
2, the official description of the use of the object pool concept of the memlist, in the case of large amounts of data will cause the Render object list is lost, which is similar to small programs. So this project does not use the memlist approach
3, currently encountering two problems
(a) The sub-components in the list are not refreshed when rendering is judged using if and for. The condition in if is modified, but the interface is not refreshed
(b) nesting for loops in the list, and if the subcomponents of the FOR loop are reusable DOM tags, the DOM nodes are incorrectly reused. As shown in, the picture of a Weibo appears in the B Weibo.
for The //image tag appears in a different sub-element because it is reused if= "{{Showindex = = = Picindex}}" class= "picture {{Enterclass}}" src= "{{pic}}" @swipe = "changepic ()" ></ Image> </block>
the span in//text is a row element and will not be reused, so it is no problem to nest such components in the list. Here the code only does the description, the format has the problem for = "(Picindex, pic) in Backpics" > if= "{{Showindex = = = Picindex}}" class= "Picture {{Enterclass}}" src= "{{pic}}" @swipe = "changepic ()" ></span> </block> </ Text>>
4. Rich Text
The official Rich-text supports eating fast HTML strings, so the native HTML string returned by the microblogging interface contains icons and other expressions that cannot be used.
The project refers to the practice in small programs, first using regular filtering, and traversing the formation of the content array, and then in the template for loop out. See Src/components/richcontent.ux for details.
There is a problem:
Using text embedded in span and A,text does not support image or other forms of images, and cannot display emoji icon.
If you embed text, a, and image with a Div, you will encounter the problem of element confusion in list.
5, gallery display large map
To begin with, develop a gallery component, put it in the global, and then control through the message, but still encounter the list rendering problem.
Currently the use of the page approach, through routing parameters. One is to be able to do fullscreen, the second is to avoid the list optimization problem. See Src/pages/gallery/index.ux for details.
Using stack overlay features, you can put small and loaded animations below, and then wait for a larger image to load, and the large map will overwrite the small image and load the animation.
<stack class= "Gallery" > <block for= "(Picindex, pic) in Backpics" >//In the list has already loaded the small picture, guarantees the user to be able to see the content first time, although is vague<imageif= "{{Showindex = = = Picindex}}" class= "picture {{Enterclass}}" src= "{{pic}}" @swipe = "changepic ()" ></image> </block> <progress class= "load-progress" type= "circular" ></progress>//Loading animations<block for= "(Picindex, pic) in Showpics" >//Large image, wait for the overlay to overwrite the small image and animation after loading<imageif= "{{Showindex = = = Picindex}}" class= "picture {{Enterclass}}" src= "{{pic}}" @longpress = "longpress" @swipe = "changepic () "></image> </block> <div show=" {{showindex > 0}} "class=" button Left-button "@click =" changepic ( {direction: ' right '}) ' ><text>?</text></div> <div show= "{{Showindex < showpics.length-1}}" class= "button right-b Utton "@click =" Changepic ({direction: ' Left '}) "><text>?</text></div> <div class=" button Back-button "@click =" Closegallery "><text>︽</text></div> </stack>
There is a problem:
The unified element does not support simultaneous monitoring of the click and Swiper events, so the click-to-return list cannot be implemented
Large-scale rendering problem, the measured large image in the aspect ratio does not exceed the screen, the display is normal; exceeding (such as a long picture) causes rendering to blur, the longer the more blurred:
5. Style class Problems
- There is no style inheritance, the font-size written in the DIV is only invalid and must be written in the corresponding text or span
- Justify-content does not support space-around, can be wrapped in containers, container padding implementation.
- Position only fixed, to achieve relative with padding adjustment position
- Border does not support border-left writing, need to border:0px solid #eeeeee; border-left:1px;
5, Debugger
In the debugger, click Start Debugging, in the code to hit the debugger, you can debug.
Iii. Summary
Fast application of the whole is still in the beat stage, many features have problems, I hope the official resolution soon. The overall wording to the small program, similar to the mpvue of things should also appear, performance is better than small programs, the current ecological small, the biggest problem is to promote ...
before thinking of several directions, there are two in the exploration, there are results to write it again. 1) Component Yes2) Routing√3) Native Interface√4) Global state management: Consider inheriting MOBX or similar flux components5) Type detection: Consider using TS
"Notes" Fast Application Quickapp (HAP)--building a microblog application