Skip to content

Commit

Permalink
Merge branch 'master' into 'develop-data-render-script'
Browse files Browse the repository at this point in the history
Merge Master to develop-data-render-script



See merge request !190634
  • Loading branch information
YorkShen committed Dec 10, 2018
2 parents d8c4ad9 + d4d1aa2 commit 33dec8d
Show file tree
Hide file tree
Showing 45 changed files with 270 additions and 122 deletions.
28 changes: 20 additions & 8 deletions HOW-TO-BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,29 @@ Move `min` version to Native SDK folder, which will be used by native SDK build.
> `cp packages/weex-js-framework/index.min.js android_sdk/assets/main.js`
## Build Android SDK
Make sure you have gradle installed, see more details about 'how to install gradle' on the [gradle website](https://gradle.org/install).
At the root folder of the project, execute
> `$ gradle wrapper --gradle-version 2.14.1`

Create a Gradle setting file
> `$ echo 'include ":android_sdk"'>settings.gradle`
check env

Build the SDK
> `$ ./gradlew :android_sdk:assemble -PasfRelease`
- you have gradle installed, see more details about 'how to install gradle' on the [gradle website](https://gradle.org/install).
- NDK r16 [link](https://developer.android.com/ndk/)
- edit local.propteries (in `Android` dir)

```
ndk.dir=/Users/{user}/Library/Android/sdk/ndk-bundle-r16
sdk.dir=/Users/{user}/Library/Android/sdk
```

then do buid

> cd Android/sdk
> ../gradlew clean assemble

artifacts path:

` android/sdk/build/outputs/aar`

Now, you can see the artifacts under `android_sdk/build/output/`.
You can now import the aar file to your android project.

## Build iOS SDK
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A framework for building Mobile cross-platform UI.

[![CircleCI](https://circleci.com/gh/alibaba/weex/tree/dev.svg?style=svg&circle-token=b83b047a3a01f6ec26458a455530a5ddc261925f)](https://circleci.com/gh/alibaba/weex/tree/dev)
[![Build Status](https://travis-ci.org/apache/incubator-weex.svg?branch=master)](https://travis-ci.org/apache/incubator-weex/)

| platform | status |
| -------- | ------ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public static String findSoPath(String libName) {
WXLogUtils.e(libName + "'s Path is" + soPath);
return soFile.getAbsolutePath();
} else {
WXLogUtils.e(libName + "'s Path is " + soPath + " but file is not exist");
WXLogUtils.e(libName + "'s Path is " + soPath + " but file does not exist");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ public int callUpdateAttrs(String instanceId, String ref, HashMap<String, String

@Override
@CalledByNative
public int callLayout(String instanceId, String ref, int top, int bottom, int left, int right, int height, int width, int index) {
public int callLayout(String instanceId, String ref, int top, int bottom, int left, int right, int height, int width, boolean isRTL, int index) {
int errorCode = IWXBridge.INSTANCE_RENDERING;
try {
errorCode = WXBridgeManager.getInstance().callLayout(instanceId, ref, top, bottom, left, right, height, width, index);
errorCode = WXBridgeManager.getInstance().callLayout(instanceId, ref, top, bottom, left, right, height, width, isRTL, index);
} catch (Throwable e) {
//catch everything during call native.
if (WXEnvironment.isApkDebugable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ public void createInstance(final String instanceId, final Script template,
final Map<String, Object> options, final String data) {
final WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
if (instance == null) {
WXLogUtils.e("WXBridgeManager", "createInstance failed, SDKInstance is not exist");
WXLogUtils.e("WXBridgeManager", "createInstance failed, SDKInstance does not exist");
return;
}
if (TextUtils.isEmpty(instanceId) || template == null || template.isEmpty() || mJSHandler == null) {
Expand Down Expand Up @@ -2753,7 +2753,7 @@ public int callUpdateAttrs(String instanceId, String ref, HashMap<String, String
return IWXBridge.INSTANCE_RENDERING;
}

public int callLayout(String pageId, String ref, int top, int bottom, int left, int right, int height, int width, int index) {
public int callLayout(String pageId, String ref, int top, int bottom, int left, int right, int height, int width, boolean isRTL, int index) {

if (TextUtils.isEmpty(pageId) || TextUtils.isEmpty(ref)) {
if (WXEnvironment.isApkDebugable()){
Expand Down Expand Up @@ -2788,6 +2788,7 @@ public int callLayout(String pageId, String ref, int top, int bottom, int left,
GraphicPosition position = new GraphicPosition(left, top, right, bottom);
GraphicActionAddElement addAction = instance.getInActiveAddElementAction(ref);
if(addAction!=null) {
addAction.setRTL(isRTL);
addAction.setSize(size);
addAction.setPosition(position);
if(!TextUtils.equals(ref, WXComponent.ROOT)) {
Expand All @@ -2797,7 +2798,7 @@ public int callLayout(String pageId, String ref, int top, int bottom, int left,
instance.removeInActiveAddElmentAction(ref);
}
else {
final BasicGraphicAction action = new GraphicActionLayout(instance, ref, position, size);
final BasicGraphicAction action = new GraphicActionLayout(instance, ref, position, size, isRTL);
WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(action.getPageId(), action);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int callUpdateStyle(String instanceId, String ref,
int callUpdateAttrs(String instanceId, String ref,
HashMap<String, String> attrs);

int callLayout(String instanceId, String ref, int top, int bottom, int left, int right, int height, int width, int index);
int callLayout(String instanceId, String ref, int top, int bottom, int left, int right, int height, int width, boolean isRTL, int index);

int callCreateFinish(String instanceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public enum WXErrorCode {
/**
* Single progress init error
*/
WX_ERR_SINGLE_PROCESS_DLOPEN_FILE_NOT_EXIST("-1004", "so file is not exist",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),
WX_ERR_SINGLE_PROCESS_DLOPEN_FILE_NOT_EXIST("-1004", "so file does not exist",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

WX_ERR_SINGLE_PROCESS_DLOPEN_FLAIED("-1005", "dlopen so file failed",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

Expand All @@ -170,7 +170,7 @@ public enum WXErrorCode {

WX_JS_FRAMEWORK_REINIT_MULPROCESS_FAILED("-1009", "js framework reinit multiProcess failed",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

WX_JS_FRAMEWORK_INIT_FAILED("-1010", "js framework init failed",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),
WX_JS_FRAMEWORK_INIT_FAILED("-1010", "js framework init failed",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

WX_JS_FRAMEWORK_INIT_SINGLE_PROCESS_SUCCESS("-1011", "js framework init success in single process",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import android.text.style.AbsoluteSizeSpan;
import android.text.style.AlignmentSpan;
import android.text.style.ForegroundColorSpan;
import android.support.annotation.RestrictTo;
import android.support.annotation.RestrictTo.Scope;
import android.support.annotation.WorkerThread;

import com.taobao.weex.WXSDKManager;
import com.taobao.weex.common.Constants;
Expand Down Expand Up @@ -202,6 +205,25 @@ private void updateStyleAndText() {
mText = WXAttr.getValue(mComponent.getAttrs());
}

/**
* Force relayout the text, the text must layout before invoke this method.
*
* Internal method, do not invoke unless you what what you are doing
* @param isRTL
*/
@RestrictTo(Scope.LIBRARY)
@WorkerThread
public void forceRelayout(){
//Generate Spans
layoutBefore();

//Measure
measure(previousWidth, Float.NaN, MeasureMode.EXACTLY, MeasureMode.UNSPECIFIED);

//Swap text layout to UI Thread
layoutAfter(previousWidth, Float.NaN);
}

/**
* Record the property according to the given style
*
Expand Down Expand Up @@ -232,7 +254,7 @@ private void updateStyleImp(Map<String, Object> style) {
if (style.containsKey(Constants.Name.FONT_FAMILY)) {
mFontFamily = WXStyle.getFontFamily(style);
}
mAlignment = WXStyle.getTextAlignment(style, mComponent.isNativeLayoutRTL());
mAlignment = WXStyle.getTextAlignment(style, mComponent.isLayoutRTL());
textOverflow = WXStyle.getTextOverflow(style);
int lineHeight = WXStyle.getLineHeight(style, mComponent.getViewPortWidth());
if (lineHeight != UNSET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class GraphicActionAddElement extends GraphicActionAbstractAddElement {
private WXComponent child;
private GraphicPosition layoutPosition;
private GraphicSize layoutSize;
private boolean isLayoutRTL;

public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref,
String componentType, String parentRef,
Expand Down Expand Up @@ -145,6 +146,12 @@ public GraphicActionAddElement(@NonNull WXSDKInstance instance, String ref,

}

@RestrictTo(Scope.LIBRARY)
@WorkerThread
public void setRTL(boolean isRTL){
this.isLayoutRTL = isRTL;
}

@RestrictTo(Scope.LIBRARY)
@WorkerThread
public void setSize(GraphicSize graphicSize){
Expand Down Expand Up @@ -173,6 +180,7 @@ public void executeAction() {
parent.addChild(child, mIndex);
parent.createChildViewAt(mIndex);

child.setIsLayoutRTL(isLayoutRTL);
if(layoutPosition !=null && layoutSize != null) {
child.setDemission(layoutSize, layoutPosition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ public class GraphicActionLayout extends BasicGraphicAction {

private final GraphicPosition mLayoutPosition;
private final GraphicSize mLayoutSize;
private final boolean mIsLayoutRTL;

public GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition layoutPosition, GraphicSize layoutSize) {
public GraphicActionLayout(WXSDKInstance instance, String ref, GraphicPosition layoutPosition, GraphicSize layoutSize, boolean isRTL) {
super(instance, ref);
this.mLayoutPosition = layoutPosition;
this.mLayoutSize = layoutSize;
this.mIsLayoutRTL = isRTL;
}

@Override
Expand All @@ -40,6 +42,7 @@ public void executeAction() {
return;
}

component.setIsLayoutRTL(mIsLayoutRTL);
component.setDemission(mLayoutSize, mLayoutPosition);
component.setSafeLayout(component);
component.setPadding(component.getPadding(), component.getBorder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ public void layoutAfter(float computedWidth, float computedHeight) {
});
}

@Override
protected void layoutDirectionDidChanged(boolean isRTL) {
String alignStr = (String) getStyles().get(Constants.Name.TEXT_ALIGN);
int textAlign = getTextAlign(alignStr);
if (textAlign <= 0) {
textAlign = Gravity.START;
}
if (getHostView() instanceof WXEditText) {
getHostView().setGravity(textAlign | getVerticalGravity());
}
}

protected final float getMeasuredLineHeight() {
return mLineHeight != UNSET && mLineHeight > 0 ? mLineHeight : mPaint.getFontMetrics(null);
}
Expand Down Expand Up @@ -752,10 +764,12 @@ public void run() {
}

private int getTextAlign(String textAlign) {
int align = Gravity.START;
boolean isRTL = isLayoutRTL();
int align = isRTL ? Gravity.END : Gravity.START;
if (TextUtils.isEmpty(textAlign)) {
return align;
}

if (textAlign.equals(Constants.Value.LEFT)) {
align = Gravity.START;
} else if (textAlign.equals(Constants.Value.CENTER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple

private int mAbsoluteY = 0;
private int mAbsoluteX = 0;
private boolean isLastLayoutDirectionRTL = false;
@Nullable
private Set<String> mGestureType;

Expand Down Expand Up @@ -184,7 +185,7 @@ public abstract class WXComponent<T extends View> extends WXBasicComponent imple
private boolean waste = false;
public boolean isIgnoreInteraction = false;

private ContentBoxMeasurement contentBoxMeasurement;
protected ContentBoxMeasurement contentBoxMeasurement;
private WXTransition mTransition;
private GraphicSize mPseudoResetGraphicSize;
@Nullable
Expand Down Expand Up @@ -248,35 +249,6 @@ public void setMarginsSupportRTL(ViewGroup.MarginLayoutParams lp, int left, int
}
}

public boolean isNativeLayoutRTL() {
return NativeRenderObjectUtils.nativeRenderObjectGetLayoutDirectionFromPathNode(this.getRenderObjectPtr()) == NativeRenderLayoutDirection.rtl;
}

public static boolean isLayoutRTL(WXComponent cmp) {
if (cmp == null) return false;

View view = cmp.getHostView();
if (ViewCompat.isLayoutDirectionResolved(view)) {
return ViewCompat.getLayoutDirection(view) == View.LAYOUT_DIRECTION_RTL;
} else if (cmp.getParent() != null){
return isLayoutRTL(cmp.getParent());
} else {
return isLayoutRTL((ViewGroup) view.getParent());
}
}

public static boolean isLayoutRTL(ViewGroup viewGroup) {
if (viewGroup == null) return false;

if (ViewCompat.isLayoutDirectionResolved(viewGroup)) {
return ViewCompat.getLayoutDirection(viewGroup) == View.LAYOUT_DIRECTION_RTL;
} else if (viewGroup.getParent() instanceof ViewGroup) {
return isLayoutRTL((ViewGroup) viewGroup.getParent());
} else {
return false;
}
}

public void updateStyles(WXComponent component) {
if (component != null) {
updateProperties(component.getStyles());
Expand Down Expand Up @@ -944,6 +916,13 @@ public void setLayout(WXComponent component) {
setMargins(component.getMargin());
setBorders(component.getBorder());

boolean isRTL = component.isLayoutRTL();
setIsLayoutRTL(isRTL);
if (isRTL != component.isLastLayoutDirectionRTL) {
component.isLastLayoutDirectionRTL = isRTL;
layoutDirectionDidChanged(isRTL);
}

parseAnimation();

boolean nullParent = mParent == null;//parent is nullable
Expand Down Expand Up @@ -1050,6 +1029,16 @@ private void setComponentLayoutParams(int realWidth, int realHeight, int realLef
}
}

/**
* layout direction is changed
* basic class is a empty implementation
* subclass can override this method do some RTL necessary things
* such as WXText
*/
protected void layoutDirectionDidChanged(boolean isRTL) {

}

private void recordInteraction(int realWidth,int realHeight){
if (!mIsAddElementToTree){
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public void setMarginsSupportRTL(ViewGroup.MarginLayoutParams lp, int left, int
} else {
if (lp instanceof FrameLayout.LayoutParams) {
FrameLayout.LayoutParams lp_frameLayout = (FrameLayout.LayoutParams) lp;
if (this.isNativeLayoutRTL()) {
if (isLayoutRTL()) {
lp_frameLayout.gravity = Gravity.RIGHT | Gravity.TOP;
lp.setMargins(right, top, left, bottom);
} else {
Expand All @@ -415,7 +415,7 @@ public void setLayout(WXComponent component) {
return;
}
if (component.getHostView() != null) {
int layoutDirection = component.isNativeLayoutRTL() ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
int layoutDirection = component.isLayoutRTL() ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR;
ViewCompat.setLayoutDirection(component.getHostView(), layoutDirection);
}
super.setLayout(component);
Expand Down Expand Up @@ -489,7 +489,7 @@ public void onLayoutChange(View view, int left, int top, int right, int bottom,
scrollView.post(new Runnable() {
@Override
public void run() {
if (isNativeLayoutRTL()) {
if (isLayoutRTL()) {
int mw = frameLayout.getMeasuredWidth();
scrollView.scrollTo(mw, component.getScrollY());
} else {
Expand Down Expand Up @@ -784,7 +784,7 @@ public void scrollTo(WXComponent component, Map<String, Object> options) {

int viewYInScroller = component.getAbsoluteY() - getAbsoluteY();
int viewXInScroller = 0;
if (this.isNativeLayoutRTL()) {
if (this.isLayoutRTL()) {
// if layout direction is rtl, we need calculate rtl scroll x;
if (getInnerView().getChildCount() > 0) {
int totalWidth = getInnerView().getChildAt(0).getWidth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void run() {
@Override
public void setLayout(WXComponent component) {
if (mAdapter != null) {
mAdapter.setLayoutDirectionRTL(this.isNativeLayoutRTL());
mAdapter.setLayoutDirectionRTL(this.isLayoutRTL());
}
super.setLayout(component);
}
Expand Down Expand Up @@ -291,7 +291,7 @@ private int getRealIndex(int idx) {

if (mAdapter.getRealCount() > 0) {
if(idx >= mAdapter.getRealCount()) retIdx = mAdapter.getRealCount() - 1;
if (isNativeLayoutRTL()) {
if (isLayoutRTL()) {
retIdx = mAdapter.getRealCount() - 1 - retIdx;
}
}
Expand Down
Loading

0 comments on commit 33dec8d

Please sign in to comment.