alibaba/Virtualview-Android

Name: Virtualview-Android

Owner: Alibaba

Description: A light way to build UI in custom XML.

Created: 2017-12-05 03:25:05.0

Updated: 2018-05-24 15:15:59.0

Pushed: 2018-05-24 08:19:33.0

Homepage: http://tangram.pingguohe.net/

Size: 805

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

VirtualView

????

Projects of Tangram
Android
iOS
Server

In the system of Android, the structure of a page can be modified by config dynamically while the business components is written in native code which can only be updated with App release. This library, VirtualView, is born to solve this problem. It provides a serial of basic component and layout component like that in Android and builds business component via XML, then compiles the XML file into binary data and deploys it to App with VirutalView sdk to render the view. When the binary data comes from XML deploys dynamically, the business component on released App can be updated dynamically.

The way to write XML template and serialize to binary is borrowed from Android's native development. But in VirtualView it is simplified and enhanced with simple EL expression and logic expression, make it more suitable to Android system.

And just as its name implies, this library introduces a concept of virtual view, which allows the basic component and layout defined in XML to directly render on the canvas of container with component's size and position calculated. This makes the final view in Android system is flatten and render performance is imporved.

XML template to build business component dynamically and virtual view to improve performance, these are two most important reason to use VirtualView.

For more information, see this.

Features
Real-time compile tools

I'm docs

User Guide
Use It Independently
Import Library

Please find the latest version in release notes. The newest version has been upload to jcenter and MavenCentral, make sure you have added at least one of these repositories. As follow:

For gradle:

ile ('com.alibaba.android:virtualview:1.0.5@aar') {
transitive = true

Or in maven: pom.xml

endency>
roupId>com.alibaba.android</groupId>
rtifactId>virtualview</artifactId>
ersion>1.0.5</version>
ype>aar</type>
pendency>

Init a VafContext instance,

ontext vafContext = new VafContext(mContext.getApplicationContext());

Init an image loader.(Optional) If you run Demo App and use NImage and VImage, this work has to been done. In product App, you are suggested to use your own image component to replace such build-in ones because a product level App always have custom image library.

ontext.loadImageLoader(mContext.getApplicationContext());

Init ViewManager instance,

Manager viewManager = vafContext.getViewManager();
Manager.init(mContext.getApplicationContext());

Load template binary data compiled by VirtualView Tools. There are to ways to load, one way is load byte-array directly(suggested):

Manager.loadBinBufferSync(TMALLCOMPONENT1.BIN);
Manager.loadBinBufferSync(TMALLCOMPONENT2.BIN);
..

the other way is load from file?

Manager.loadBinFileSync(TMALLCOMPONENT1_PATH);
Manager.loadBinFileSync(TMALLCOMPONENT2_PATH);
..

If you have developed custom basic components, register their builders(Guide to develop custom basic components here):

Manager.getViewFactory().registerBuilder(BizCommon.TM_PRICE_TEXTVIEW, new TMPriceView.Builder());
Manager.getViewFactory().registerBuilder(BizCommon.TM_TOTAL_CONTAINER, new TotalContainer.Builder());

Register event handler for click or exposure: (Information for event handler here)

ontext.getEventManager().register(EventManager.TYPE_Click, new IEventProcessor() {

@Override
public boolean process(EventData data) {
    //handle here
    return true;
}

ontext.getEventManager().register(EventManager.TYPE_Exposure, new IEventProcessor() {

@Override
public boolean process(EventData data) {
    //handle here
    return true;
}

Build final view instance by name and add it to existing layout,

 container = vafContext.getContainerService().getContainer(name, true);
earLayout.addView(container);

Set data to view to bind it to views,

tainer iContainer = (IContainer)container;
Object json = getJSONDataFromAsset(data);
json != null) {
iContainer.getVirtualView().setVData(json);

Of course before running your own components, you should learn to write XML template for your components. In Demo App there is a few templates to show how to do it. Try to learn to write one with the help of samples and guide.

Use It in Tangram

Use VirtualView in Tangram is just the same as using it independently while a lot of work has been done in Tangram, users only need to register components and template data to Tangram, provide event handler.

Register Tangram component developed by VirtualView with component's type,

ram.Builder builder = Tangram.newBuilder(activity);
der.registerVirtualView("tmallcomponent1");
der.registerVirtualView("tmallcomponent2");

After TangramEngine is built, load each component's binary data,

ramEngine.setVirtualViewTemplate(TMALLCOMPONENT1.BIN);
ramEngine.setVirtualViewTemplate(TMALLCOMPONENT2.BIN);

Register custom basic component builder if necessary,

Manager viewManager = tangramEngine.getService(ViewManager.class);
Manager.getViewFactory().registerBuilder(BizCommon.TM_PRICE_TEXTVIEW, new TMPriceView.Builder());

Register event handler,

ontext vafContext = tangramEngine.getService(VafContext.class);
ontext.getEventManager().register(EventManager.TYPE_Click, new IEventProcessor() {

@Override
public boolean process(EventData data) {
    //handle here
    return true;
}

ontext.getEventManager().register(EventManager.TYPE_Exposure, new IEventProcessor() {

@Override
public boolean process(EventData data) {
    //handle here
    return true;
}

More about running VirtualView in Tangram can be found here.

Contributing

Before you open an issue or create a pull request, please read Contributing Guide first.

LICENSE

VirtualView is available under the MIT license.

WeChatGroup

Search tangram_ or scan the QR code above to be invited in WeChat.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.