Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, copy, nullable) RCTSurfaceHostingViewActivityIndicatorViewFactory activityIndicatorViewFactory;

/**
* When set to `YES`, the activity indicator is not automatically hidden when the Surface stage changes.
* In this scenario, users should invoke `hideActivityIndicator` to remove it.
*
* @param disabled: if `YES`, the auto-hide is disabled. Otherwise the loading view will be hidden automatically
*/
- (void)disableActivityIndicatorAutoHide:(BOOL)disabled;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ @implementation RCTSurfaceHostingView {
UIView *_Nullable _activityIndicatorView;
UIView *_Nullable _surfaceView;
RCTSurfaceStage _stage;
BOOL _autoHideDisabled;
}

RCT_NOT_IMPLEMENTED(-(instancetype)init)
Expand All @@ -36,6 +37,7 @@ - (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface
if (self = [super initWithFrame:CGRectZero]) {
_surface = surface;
_sizeMeasureMode = sizeMeasureMode;
_autoHideDisabled = NO;

_surface.delegate = self;
_stage = surface.stage;
Expand Down Expand Up @@ -124,6 +126,10 @@ - (void)setSizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
_sizeMeasureMode = sizeMeasureMode;
[self _invalidateLayout];
}
- (void)disableActivityIndicatorAutoHide:(BOOL)disabled
{
_autoHideDisabled = disabled;
}

#pragma mark - isActivityIndicatorViewVisible

Expand Down Expand Up @@ -162,7 +168,16 @@ - (void)setIsSurfaceViewVisible:(BOOL)visible
_surfaceView = _surface.view;
_surfaceView.frame = self.bounds;
_surfaceView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:_surfaceView];
if (_activityIndicatorView && _autoHideDisabled) {
// The activity indicator is still showing and the surface is set to
// prevent the auto hide. This means that the application will take care of
// hiding it when it's ready.
// Let's add the surfaceView below the activity indicator so it's ready once
// the activity indicator is hidden.
[self insertSubview:_surfaceView belowSubview:_activityIndicatorView];
} else {
[self addSubview:_surfaceView];
}
} else {
[_surfaceView removeFromSuperview];
_surfaceView = nil;
Expand Down Expand Up @@ -204,7 +219,7 @@ - (void)_invalidateLayout
- (void)_updateViews
{
self.isSurfaceViewVisible = RCTSurfaceStageIsRunning(_stage);
self.isActivityIndicatorViewVisible = RCTSurfaceStageIsPreparing(_stage);
self.isActivityIndicatorViewVisible = _autoHideDisabled || RCTSurfaceStageIsPreparing(_stage);
}

- (void)didMoveToWindow
Expand Down