FLBFlutterContainerManager.m 2.53 KB
Newer Older
Jidong Chen's avatar
init  
Jidong Chen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * The MIT License (MIT)
 * 
 * Copyright (c) 2019 Alibaba Group
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

25
#import "FLBFlutterContainerManager.h"
Jidong Chen's avatar
init  
Jidong Chen committed
26

27
@interface FLBFlutterContainerManager()
Jidong Chen's avatar
init  
Jidong Chen committed
28 29 30 31
@property (nonatomic,strong) NSMutableArray *idStk;
@property (nonatomic,strong) NSMutableDictionary *existedID;
@end

32
@implementation FLBFlutterContainerManager
Jidong Chen's avatar
init  
Jidong Chen committed
33 34 35 36 37 38 39 40 41 42 43

- (instancetype)init
{
    if (self = [super init]) {
        _idStk= [NSMutableArray new];
        _existedID = [NSMutableDictionary dictionary];
    }
    
    return self;
}

Jidong Chen's avatar
Jidong Chen committed
44
- (BOOL)contains:(id<FLBFlutterContainer>)vc
Jidong Chen's avatar
init  
Jidong Chen committed
45 46 47 48 49 50 51 52
{
    if (vc) {
        return _existedID[vc.uniqueIDString]?YES:NO;
    }
    
    return NO;
}

Jidong Chen's avatar
Jidong Chen committed
53
- (void)addUnique:(id<FLBFlutterContainer>)vc
Jidong Chen's avatar
init  
Jidong Chen committed
54 55 56 57 58
{
    if (vc) {
        if(!_existedID[vc.uniqueIDString]){
            [_idStk addObject:vc.uniqueIDString];
        }
余玠's avatar
余玠 committed
59
        _existedID[vc.uniqueIDString] = vc.name;
Jidong Chen's avatar
init  
Jidong Chen committed
60
    }
余玠's avatar
余玠 committed
61
#if DEBUG
余玠's avatar
余玠 committed
62 63
    [self dump:@"ADD"];
#endif
Jidong Chen's avatar
init  
Jidong Chen committed
64 65
}

Jidong Chen's avatar
Jidong Chen committed
66
- (void)remove:(id<FLBFlutterContainer>)vc
Jidong Chen's avatar
init  
Jidong Chen committed
67 68 69 70 71
{
    if (vc) {
        [_existedID removeObjectForKey:vc.uniqueIDString];
        [_idStk removeObject:vc.uniqueIDString];
    }
余玠's avatar
余玠 committed
72
#if DEBUG
余玠's avatar
余玠 committed
73 74
    [self dump:@"REMOVE"];
#endif
Jidong Chen's avatar
init  
Jidong Chen committed
75 76 77 78 79 80 81
}

- (NSString *)peak
{
    return _idStk.lastObject;
}

82 83 84 85
- (NSInteger)pageCount{
    return _idStk.count;
}

余玠's avatar
余玠 committed
86
#if DEBUG
余玠's avatar
余玠 committed
87 88 89 90 91 92 93 94
- (void)dump:(NSString*)flag{
    NSMutableString *log = [[NSMutableString alloc]initWithFormat:@"[DEBUG]--%@--PageStack uid/name", flag];
    for(NSString *uid in _idStk){
        [log appendFormat:@"-->%@/%@",uid, _existedID[uid]];
    }
    NSLog(@"%@\n", log);
}
#endif
Jidong Chen's avatar
init  
Jidong Chen committed
95
@end