Skip to content

Commit

Permalink
Merge branch 'master' into android-feature-dev-tools-exception
Browse files Browse the repository at this point in the history
* master:
  close apache#790,close apache#796,close apache#801,close apache#803
  close apache#884,close apache#886,close apache#889
  -[test] close apache#887
  resolve apache#887
  [WEEX-132][iOS] support text writing direction from right to left
  [WEEX-133][iOS] support word-wrap on iOS when drawing text
  [WEEX-129][android] Appear Event Be Fired Multi Times And Event not watch be fired
  [WEEX-124][android]fix android bug
  * [android] fix page oin slider can not receive the lifecycle callbacks
  • Loading branch information
atomtong committed Nov 21, 2017
2 parents b3d61fe + 1175064 commit e2a98e6
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public void executeDom(DOMActionContext context) {
}

WXDomObject root = context.getDomByRef(WXDomObject.ROOT);
if(root == null){
return;
}
mLayoutHeight = (int)root.getLayoutHeight();
mLayoutWidth = (int)root.getLayoutWidth();
context.postRenderTask(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1661,21 +1661,14 @@ protected boolean containsEvent(String event){
}

public void notifyAppearStateChange(String wxEventType,String direction){
if(containsEvent(Constants.Event.APPEAR) || containsEvent(Constants.Event.DISAPPEAR)) {
Map<String, Object> params = new HashMap<>();
params.put("direction", direction);
fireEvent(wxEventType, params);
}
}

public void notifyWatchAppearDisappearEvent(String wxEventType,String direction){
if(containsEvent(wxEventType)) {
Map<String, Object> params = new HashMap<>();
params.put("direction", direction);
fireEvent(wxEventType, params);
Map<String, Object> params = new HashMap<>();
params.put("direction", direction);
fireEvent(wxEventType, params);
}
}


public boolean isUsing() {
return isUsing;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ public void destroy() {

@Override
public void onActivityResume() {
super.onActivityResume();
if (mViewPager != null && mViewPager.isAutoScroll()) {
mViewPager.startAutoScroll();
}
}

@Override
public void onActivityStop() {
super.onActivityStop();
if (mViewPager != null) {
mViewPager.pauseAutoScroll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,14 @@ public void notifyAppearStateChange(String wxEventType, String direction) {
if(getHostView()==null || mChildren==null){
return;
}
for(WXComponent component:mChildren){
if(component.getHostView()!=null && !(component.getHostView().getVisibility()==View.VISIBLE)){
wxEventType= Constants.Event.DISAPPEAR;
//appear should not notify child
if(getDomObject().getAttrs().containsKey("appearNotifyChild")){
for(WXComponent component:mChildren){
if(component.getHostView()!=null && !(component.getHostView().getVisibility()==View.VISIBLE)){
wxEventType= Constants.Event.DISAPPEAR;
}
component.notifyAppearStateChange(wxEventType,direction);
}
component.notifyAppearStateChange(wxEventType,direction);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ public void notifyAppearStateChange(int firstVisible, int lastVisible, int direc
int key = childLisener.getHostView().hashCode();
if(appear){
if(!componentDisAppearList.containsKey(key)){
childLisener.notifyWatchAppearDisappearEvent(Constants.Event.APPEAR, direction);
childLisener.notifyAppearStateChange(Constants.Event.APPEAR, direction);
List<Object> eventArgs = null;
if(childLisener.getDomObject().getEvents() != null
&& childLisener.getDomObject().getEvents().getEventBindingArgsValues() != null
Expand All @@ -1369,7 +1369,7 @@ public void notifyAppearStateChange(int firstVisible, int lastVisible, int direc
}
}else{
if(componentDisAppearList.containsKey(key)){
childLisener.notifyWatchAppearDisappearEvent(Constants.Event.DISAPPEAR, direction);
childLisener.notifyAppearStateChange(Constants.Event.DISAPPEAR, direction);
componentDisAppearList.remove(key);
}
}
Expand Down Expand Up @@ -1407,7 +1407,7 @@ public void notifyAppearStateChange(int firstVisible, int lastVisible, int direc
Set<Map.Entry<Integer, List<Object>>> eventWatcherEntries = eventWatchers.entrySet();
for(Map.Entry<Integer, List<Object>> eventWatcherEntry : eventWatcherEntries){
events.putEventBindingArgsValue(Constants.Event.DISAPPEAR, eventWatcherEntry.getValue());
component.notifyWatchAppearDisappearEvent(Constants.Event.DISAPPEAR, direction);
component.notifyAppearStateChange(Constants.Event.DISAPPEAR, direction);
}
eventWatchers.clear();
}
Expand Down
52 changes: 49 additions & 3 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ @implementation WXTextComponent
WXTextStyle _fontStyle;
NSUInteger _lines;
NSTextAlignment _textAlign;
NSString *_direction;
WXTextDecoration _textDecoration;
NSString *_textOverflow;
CGFloat _lineHeight;
Expand All @@ -128,6 +129,7 @@ @implementation WXTextComponent

BOOL _needsRemoveObserver;
NSAttributedString * _ctAttributedString;
NSString *_wordWrap;

pthread_mutex_t _ctAttributedStringMutex;
pthread_mutexattr_t _propertMutexAttr;
Expand Down Expand Up @@ -232,6 +234,8 @@ - (void)fillCSSStyles:(NSDictionary *)styles
WX_STYLE_FILL_TEXT(textOverflow, textOverflow, NSString, NO)
WX_STYLE_FILL_TEXT_PIXEL(lineHeight, lineHeight, YES)
WX_STYLE_FILL_TEXT_PIXEL(letterSpacing, letterSpacing, YES)
WX_STYLE_FILL_TEXT(wordWrap, wordWrap, NSString, YES);
WX_STYLE_FILL_TEXT(direction, direction, NSString, YES)

UIEdgeInsets padding = {
WXFloorPixelValue(self.cssNode->style.padding[CSS_TOP] + self.cssNode->style.border[CSS_TOP]),
Expand Down Expand Up @@ -438,12 +442,32 @@ - (NSMutableAttributedString *)buildCTAttributeString

NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];

// handle text direction style, default ltr
if ([_direction isEqualToString:@"rtl"]) {
if (0 == _textAlign) {
//force text right-align if don't specified any align.
_textAlign = NSTextAlignmentRight;
}
paragraphStyle.baseWritingDirection = NSWritingDirectionRightToLeft;
} else {
//if you specify NSWritingDirectionNaturalDirection, the receiver resolves the writing
//directionto eitherNSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft,
//depending on the direction for the user’s language preference setting.
paragraphStyle.baseWritingDirection = NSWritingDirectionNatural;
}

if (_textAlign) {
paragraphStyle.alignment = _textAlign;
}

// set default lineBreakMode
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
if ([[_wordWrap lowercaseString] isEqualToString:@"break-word"]) {
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
} else if ([[_wordWrap lowercaseString] isEqualToString:@"normal"]){
paragraphStyle.lineBreakMode = NSLineBreakByClipping;
} else {
// set default lineBreakMode
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
}
_truncationLine = NO;
if (_textOverflow && [_textOverflow length] > 0) {
if (_lines && [_textOverflow isEqualToString:@"ellipsis"])
Expand Down Expand Up @@ -513,6 +537,20 @@ - (NSAttributedString *)buildAttributeString

NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];

// handle text direction style, default ltr
if ([_direction isEqualToString:@"rtl"]) {
if (0 == _textAlign) {
//force text right-align if don't specified any align.
_textAlign = NSTextAlignmentRight;
}
paragraphStyle.baseWritingDirection = NSWritingDirectionRightToLeft;
} else {
//if you specify NSWritingDirectionNaturalDirection, the receiver resolves the writing
//directionto eitherNSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft,
//depending on the direction for the user’s language preference setting.
paragraphStyle.baseWritingDirection = NSWritingDirectionNatural;
}

if (_textAlign) {
paragraphStyle.alignment = _textAlign;
}
Expand Down Expand Up @@ -563,7 +601,15 @@ - (NSTextStorage *)textStorageWithWidth:(CGFloat)width
NSTextContainer *textContainer = [NSTextContainer new];
textContainer.lineFragmentPadding = 0.0;

textContainer.lineBreakMode = NSLineBreakByClipping;
if ([[_wordWrap lowercaseString] isEqualToString:@"break-word"]) {
textContainer.lineBreakMode = NSLineBreakByWordWrapping;
} else if ([[_wordWrap lowercaseString] isEqualToString:@"normal"]){
textContainer.lineBreakMode = NSLineBreakByClipping;
} else {
// set default lineBreakMode
textContainer.lineBreakMode = NSLineBreakByCharWrapping;
}

if (_textOverflow && [_textOverflow length] > 0) {
if ([_textOverflow isEqualToString:@"ellipsis"])
textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
Expand Down

0 comments on commit e2a98e6

Please sign in to comment.