Activity indicator light disappears when scrolling down

I am doing an overlay on a button with a custom node LoadingIndicatorNode

this button is placed in ASCellNode

when I scroll down and up UIActivityIndicatorView

from LoadingIndicatorNode

disappears.

Here is the LoadingIndicatorNode

class code

@implementation LoadingIndicatorNode
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setOpaque:NO];
        self.backgroundColor = [UIColor colorWithWhite:1 alpha:0.6];
        self.activityNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView * _Nonnull{
            UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: IPAD ? UIActivityIndicatorViewStyleWhiteLarge : UIActivityIndicatorViewStyleWhite];
            activity.color = [UIColor blackColor];
            activity.backgroundColor = [UIColor clearColor];
            [activity startAnimating];
            return activity;
        }];

        [self addSubnode:self.activityNode];
    }
    return self;
}

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
    ASCenterLayoutSpec *centerSpec = [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringXY sizingOptions:ASCenterLayoutSpecSizingOptionDefault child:self.activityNode];

    return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(10, 0, 10, 0) child:centerSpec];
}

@end

      

Here is some code showing how I am using it

_loadingIndicator = [[LoadingIndicatorNode alloc] init];
_loadingIndicator.hidden = YES;
[self addSubnode:_loadingIndicator];

[[[[self.viewModel.memberStatusCommand executing] not]
     distinctUntilChanged]
     subscribeNext:^(NSNumber *x) {
         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:!x.boolValue];
         _loadingIndicator.hidden = x.boolValue;
         [self updateViewModelData];
         [self setNeedsLayout];
     }];

      

Overlay from method layoutSpecThatFits:

ASOverlayLayoutSpec *overlay = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_statusButton overlay:_loadingIndicator];
    overlay.style.flexBasis = ASDimensionMake(@"50%");
    overlay.style.alignSelf = ASStackLayoutAlignSelfStretch;
    overlay.style.flexShrink = 1;
    overlay.style.flexGrow = 1;

      

+3


source to share


1 answer


Just made a weak reference to UIActivityIndicatorView

from LoadingIndicatorNode

and implemented the method didEnterVisibleState

and calledstartAnimating



- (void)didEnterVisibleState {
    [super didEnterVisibleState];
    [self.activity startAnimating];
}

      

+1


source







All Articles