Skip to content

Commit

Permalink
Support display: none; style (iOS)
Browse files Browse the repository at this point in the history
Summary:
Yes, `display: none;` did not work on iOS before this commit.
Now it "just works". It can be useful when some view needs to be hidden temporary and efficiently.

Reviewed By: javache

Differential Revision: D5173936

fbshipit-source-id: 83a03fff04dd3a872d7dd6bf673189f932906776
  • Loading branch information
shergin authored and facebook-github-bot committed Jun 21, 2017
1 parent ac3f345 commit a04322f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDictio
RCT_VIEW_BORDER_RADIUS_PROPERTY(BottomLeft)
RCT_VIEW_BORDER_RADIUS_PROPERTY(BottomRight)

RCT_REMAP_VIEW_PROPERTY(display, reactDisplay, YGDisplay)
RCT_REMAP_VIEW_PROPERTY(zIndex, reactZIndex, NSInteger)

#pragma mark - ShadowView properties
Expand Down
8 changes: 8 additions & 0 deletions React/Views/UIView+React.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import <UIKit/UIKit.h>

#import <React/RCTComponent.h>
#import <yoga/YGEnums.h>

@class RCTShadowView;

Expand All @@ -30,6 +31,13 @@
*/
@property (nonatomic, assign) UIUserInterfaceLayoutDirection reactLayoutDirection;

/**
* Yoga `display` style property. Can be `flex` or `none`.
* Defaults to `flex`.
* May be used to temporary hide the view in a very efficient way.
*/
@property (nonatomic, assign) YGDisplay reactDisplay;

/**
* The z-index of the view.
*/
Expand Down
16 changes: 16 additions & 0 deletions React/Views/UIView+React.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ - (void)removeReactSubview:(UIView *)subview
[subview removeFromSuperview];
}

#pragma mark - Display

- (YGDisplay)reactDisplay
{
return self.isHidden ? YGDisplayNone : YGDisplayFlex;
}

- (void)setReactDisplay:(YGDisplay)display
{
self.hidden = display == YGDisplayNone;
}

#pragma mark - Layout Direction

- (UIUserInterfaceLayoutDirection)reactLayoutDirection
{
if ([self respondsToSelector:@selector(semanticContentAttribute)]) {
Expand All @@ -108,6 +122,8 @@ - (void)setReactLayoutDirection:(UIUserInterfaceLayoutDirection)layoutDirection
}
}

#pragma mark - zIndex

- (NSInteger)reactZIndex
{
return self.layer.zPosition;
Expand Down

0 comments on commit a04322f

Please sign in to comment.