Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Set overflow to hidden by default on iOS to conform to Android. (
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor authored and jianhan-he committed Jun 7, 2019
1 parent 181bca5 commit 4553f0f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
3 changes: 3 additions & 0 deletions ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ - (BOOL)_handleConfigCenter
if ([configCenter respondsToSelector:@selector(configForKey:defaultValue:isDefault:)]) {
BOOL enableRTLLayoutDirection = [[configCenter configForKey:@"iOS_weex_ext_config.enableRTLLayoutDirection" defaultValue:@(YES) isDefault:NULL] boolValue];
[WXUtility setEnableRTLLayoutDirection:enableRTLLayoutDirection];

BOOL overflowHiddenByDefault = [[configCenter configForKey:@"iOS_weex_ext_config.overflowHiddenByDefault" defaultValue:@(YES) isDefault:NULL] boolValue];
[WXUtility setOverflowHiddenByDefault:overflowHiddenByDefault];
}
return NO;
}
Expand Down
4 changes: 3 additions & 1 deletion ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,11 @@ BOOL WXFloatGreaterThanWithPrecision(CGFloat a,CGFloat b,double precision);
+ (NSData *_Nonnull)base64DictToData:(NSDictionary *_Nullable)base64Dict;

+ (void)setEnableRTLLayoutDirection:(BOOL)value;

+ (BOOL)enableRTLLayoutDirection;

+ (void)setOverflowHiddenByDefault:(BOOL)value;
+ (BOOL)overflowHiddenByDefault;

+ (long) getUnixFixTimeMillis;

+ (NSArray<NSString *> *_Nullable)extractPropertyNamesOfJSValueObject:(JSValue *_Nullable)jsvalue;
Expand Down
13 changes: 13 additions & 0 deletions ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define KEY_USERNAME_PASSWORD @"com.taobao.Weex.weex123456"

static BOOL enableRTLLayoutDirection = YES;
static BOOL overflowHiddenByDefault = YES;

void WXPerformBlockOnMainThread(void (^ _Nonnull block)(void))
{
Expand Down Expand Up @@ -770,6 +771,18 @@ + (BOOL)enableRTLLayoutDirection
return enableRTLLayoutDirection;
}

# pragma mark - Overflow

+ (void)setOverflowHiddenByDefault:(BOOL)value
{
overflowHiddenByDefault = value;
}

+ (BOOL)overflowHiddenByDefault
{
return overflowHiddenByDefault;
}

#pragma mark - get deviceID
+ (NSString *)getDeviceID {
NSMutableDictionary *usernamepasswordKVPairs = (NSMutableDictionary *)[self load:KEY_USERNAME_PASSWORD];
Expand Down
24 changes: 20 additions & 4 deletions ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.mm
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,15 @@ - (void)_initViewPropertyWithStyles:(NSDictionary *)styles
_backgroundColor = styles[@"backgroundColor"] ? [WXConvert UIColor:styles[@"backgroundColor"]] : [UIColor clearColor];
_backgroundImage = styles[@"backgroundImage"] ? [WXConvert NSString:styles[@"backgroundImage"]]: nil;
_opacity = styles[@"opacity"] ? [WXConvert CGFloat:styles[@"opacity"]] : 1.0;
_clipToBounds = styles[@"overflow"] ? [WXConvert WXClipType:styles[@"overflow"]] : NO;
if ([WXUtility overflowHiddenByDefault]) {
/* If we enable overflow:hidden by default, we cannot use original "overflow" style value.
Unless js explicitly define "ios-overflow: visible", we disable clipToBounds.
*/
_clipToBounds = styles[@"iosOverflow"] ? [WXConvert WXClipType:styles[@"iosOverflow"]] : YES;
}
else {
_clipToBounds = styles[@"overflow"] ? [WXConvert WXClipType:styles[@"overflow"]] : NO;
}
_visibility = styles[@"visibility"] ? [WXConvert WXVisibility:styles[@"visibility"]] : WXVisibilityShow;
_positionType = styles[@"position"] ? [WXConvert WXPositionType:styles[@"position"]] : WXPositionTypeRelative;
_transform = styles[@"transform"] || styles[@"transformOrigin"] ?
Expand Down Expand Up @@ -227,9 +235,17 @@ - (void)_updateViewStyles:(NSDictionary *)styles
_layer.opacity = _opacity;
}

if (styles[@"overflow"]) {
_clipToBounds = [WXConvert WXClipType:styles[@"overflow"]];
_view.clipsToBounds = _clipToBounds;
if ([WXUtility overflowHiddenByDefault]) {
if (styles[@"iosOverflow"]) {
_clipToBounds = [WXConvert WXClipType:styles[@"iosOverflow"]];
_view.clipsToBounds = _clipToBounds;
}
}
else {
if (styles[@"overflow"]) {
_clipToBounds = [WXConvert WXClipType:styles[@"overflow"]];
_view.clipsToBounds = _clipToBounds;
}
}

if (styles[@"position"]) {
Expand Down
1 change: 0 additions & 1 deletion ios/sdk/WeexSDKTests/WXComponentTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ - (void)testDefaultProperties
* View
*/
XCTAssertEqual(component->_backgroundColor, [UIColor clearColor]);
XCTAssertEqual(component->_clipToBounds, NO);
XCTAssertNil(component->_view);
XCTAssertEqual(component->_opacity, 1.0);
XCTAssertEqual(component->_visibility, WXVisibilityShow);
Expand Down

0 comments on commit 4553f0f

Please sign in to comment.