Skip to content

Commit

Permalink
Merge pull request #11 from hansemannn/update-lottie-ios
Browse files Browse the repository at this point in the history
Update Lottie iOS to 1.5.1
  • Loading branch information
m1ga authored Mar 18, 2017
2 parents 0548b06 + 5b52482 commit bc95f16
Show file tree
Hide file tree
Showing 94 changed files with 1,671 additions and 979 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Appcelerator Titanium Android module for [Facebooks Keyframes](https://github.co
## Library versions:
The Titanium modules use external libraries

|Library|Build date|
|---|---|
| [Facebooks Keyframes Android](https://github.com/facebookincubator/Keyframes) | 2017/02/11 |
| [Airbnb Lottie Android](https://github.com/airbnb/lottie-android) | 2017/03/12 |
| [Facebooks Keyframes iOS](https://github.com/facebookincubator/Keyframes) | 2017/02/11 |
| [Airbnb Lottie iOS](https://github.com/airbnb/lottie-ios) | 2017/02/11 |
|Library|Platform|Version|Build Date|
|---|---|---|---|
| [Facebooks Keyframes](https://github.com/facebookincubator/Keyframes) | Android | 1.0.0 | 2017/02/11 |
| [Facebooks Keyframes](https://github.com/facebookincubator/Keyframes) | iOS | 1.0.0 | 2017/02/11 |
| [Airbnb Lottie](https://github.com/airbnb/lottie-android) | Android | 1.0.3 | 2017/03/12 |
| [Airbnb Lottie](https://github.com/airbnb/lottie-ios) | iOS | 1.5.1 | 2017/03/18 |


## Choose your view
Expand Down
3 changes: 2 additions & 1 deletion iphone/Classes/Lottie/TiAnimationLottieViewProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Please see the LICENSE included with this distribution for details.
*/
#import "TiViewProxy.h"
#import "Lottie.h"

@class LOTAnimationView;

@interface TiAnimationLottieViewProxy : TiViewProxy {
LOTAnimationView *animationView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@interface LOTAnimatableLayer : CALayer

- (instancetype)initWithDuration:(NSTimeInterval)duration NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithLayerDuration:(NSTimeInterval)duration NS_DESIGNATED_INITIALIZER;

@property (nonatomic, readonly) NSTimeInterval laAnimationDuration;
@property (nonatomic, readonly) NSTimeInterval layerDuration;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

@implementation LOTAnimatableLayer

- (instancetype)initWithDuration:(NSTimeInterval)duration {
- (instancetype)initWithLayerDuration:(NSTimeInterval)duration {
self = [super init];
if (self) {
_laAnimationDuration = duration;
_layerDuration = duration;
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// LOTCompositionLayer.h
// Pods
//
// Created by Brandon Withrow on 2/17/17.
//
//

#import <QuartzCore/QuartzCore.h>
#import "LOTAnimationView_Compat.h"

@class LOTLayerGroup;
@class LOTAssetGroup;

@interface LOTCompositionLayer : CALayer

- (instancetype)initWithLayerGroup:(LOTLayerGroup *)layerGroup
withAssetGroup:(LOTAssetGroup *)assetGroup
withBounds:(CGRect)bounds;

- (void)addSublayer:(LOTView *)view
toLayerNamed:(NSString *)layer;

- (void)layoutCustomChildLayers;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//
// LOTCompositionLayer.m
// Pods
//
// Created by Brandon Withrow on 2/17/17.
//
//

#import "LOTCompositionLayer.h"
#import "LOTPlatformCompat.h"
#import "LOTLayerView.h"
#import "LOTAnimationView_Internal.h"
#import "LOTAsset.h"
#import "LOTAssetGroup.h"

@interface LOTCustomChild : NSObject

@property (nonatomic, strong) LOTView *childView;
@property (nonatomic, weak) LOTLayerView *layer;
@property (nonatomic, assign) LOTConstraintType constraint;

@end

@implementation LOTCustomChild

@end

@implementation LOTCompositionLayer {
NSDictionary *_layerMap;
NSDictionary *_layerNameMap;
NSMutableArray *_customLayers;
}

- (instancetype)initWithLayerGroup:(LOTLayerGroup *)layerGroup
withAssetGroup:(LOTAssetGroup *)assetGroup
withBounds:(CGRect)bounds {
self = [super init];
if (self) {
self.masksToBounds = YES;
[self _setupWithLayerGroup:layerGroup withAssetGroup:assetGroup withBounds:bounds];
}
return self;
}

- (void)_setupWithLayerGroup:(LOTLayerGroup *)layerGroup
withAssetGroup:(LOTAssetGroup *)assetGroup
withBounds:(CGRect)bounds
{
if (_customLayers) {
for (LOTCustomChild *child in _customLayers) {
[child.childView.layer removeFromSuperlayer];
}
_customLayers = nil;
}

if (_layerMap) {
_layerMap = nil;
[self removeAllAnimations];
[self.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
}

if (_layerNameMap) {
_layerNameMap = nil;
}

self.bounds = bounds;

NSMutableDictionary *layerMap = [NSMutableDictionary dictionary];
NSMutableDictionary *layerNameMap = [NSMutableDictionary dictionary];

NSArray *reversedItems = [[layerGroup.layers reverseObjectEnumerator] allObjects];

CALayer *maskedLayer = nil;
for (LOTLayer *layer in reversedItems) {
LOTAsset *asset;

if (layer.referenceID) {
asset = [assetGroup assetModelForID:layer.referenceID];
}

LOTLayerView *layerView = [[LOTLayerView alloc] initWithModel:layer inLayerGroup:layerGroup];

if (asset.layerGroup) {
LOTCompositionLayer *precompLayer = [[LOTCompositionLayer alloc] initWithLayerGroup:asset.layerGroup
withAssetGroup:assetGroup
withBounds:layer.layerBounds];
precompLayer.frame = layer.layerBounds;
[layerView LOT_addChildLayer:precompLayer];
}

layerMap[layer.layerID] = layerView;
layerNameMap[layer.layerName] = layerView;
if (maskedLayer) {
maskedLayer.mask = layerView;
maskedLayer = nil;
} else {
if (layer.matteType == LOTMatteTypeAdd) {
maskedLayer = layerView;
}
[self addSublayer:layerView];
}
}
_layerMap = layerMap;
_layerNameMap = layerNameMap;
}

- (void)layoutCustomChildLayers {
if (!_customLayers.count) {
return;
}

for (LOTCustomChild *child in _customLayers) {
switch (child.constraint) {
case LOTConstraintTypeAlignToLayer:
child.childView.frame = child.layer.bounds;
break;
case LOTConstraintTypeAlignToBounds: {
CGRect selfBounds = self.frame;
CGRect convertedBounds = [child.childView.layer.superlayer convertRect:selfBounds fromLayer:self];
child.childView.layer.frame = convertedBounds;
} break;
default:
break;
}
}
}

- (void)addSublayer:(LOTView *)view
toLayerNamed:(NSString *)layer {
LOTConstraintType constraint = LOTConstraintTypeAlignToBounds;
LOTLayerView *layerObject = _layerNameMap[layer];
LOTCustomChild *newChild = [[LOTCustomChild alloc] init];
newChild.constraint = constraint;
newChild.childView = view;

if (!layer) {
NSException* layerNotFoundExpection = [NSException exceptionWithName:@"LayerNotFoundException"
reason:@"The required layer was not specified."
userInfo:nil];
@throw layerNotFoundExpection;
} else {
newChild.layer = layerObject;
[layerObject.superlayer insertSublayer:view.layer above:layerObject];

view.layer.mask = layerObject;
}

if (!_customLayers) {
_customLayers = [NSMutableArray array];
}
[_customLayers addObject:newChild];
[self layoutCustomChildLayers];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
stroke:(LOTShapeStroke *)stroke
trim:(LOTShapeTrimPath *)trim
transform:(LOTShapeTransform *)transform
withDuration:(NSTimeInterval)duration;
withLayerDuration:(NSTimeInterval)duration;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ - (instancetype)initWithEllipseShape:(LOTShapeCircle *)circleShape
stroke:(LOTShapeStroke *)stroke
trim:(LOTShapeTrimPath *)trim
transform:(LOTShapeTransform *)transform
withDuration:(NSTimeInterval)duration {
self = [super initWithDuration:duration];
withLayerDuration:(NSTimeInterval)duration {
self = [super initWithLayerDuration:duration];
if (self) {
_circle = circleShape;
_stroke = stroke;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
fill:(LOTShapeFill *)previousFill
stroke:(LOTShapeStroke *)previousStroke
trimPath:(LOTShapeTrimPath *)previousTrimPath
withDuration:(NSTimeInterval)duration;
withLayerDuration:(NSTimeInterval)duration;

@property (nonatomic, readonly) LOTShapeGroup *shapeGroup;
@property (nonatomic, readonly) LOTShapeTransform *shapeTransform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ - (instancetype)initWithShapeGroup:(LOTShapeGroup *)shapeGroup
fill:(LOTShapeFill *)previousFill
stroke:(LOTShapeStroke *)previousStroke
trimPath:(LOTShapeTrimPath *)previousTrimPath
withDuration:(NSTimeInterval)duration {
self = [super initWithDuration:duration];
withLayerDuration:(NSTimeInterval)duration {
self = [super initWithLayerDuration:duration];
if (self) {
_shapeGroup = shapeGroup;
_shapeTransform = previousTransform;
Expand Down Expand Up @@ -73,7 +73,7 @@ - (void)_setupShapeGroupWithFill:(LOTShapeFill *)previousFill
stroke:currentStroke
trim:currentTrim
transform:currentTransform
withDuration:self.laAnimationDuration];
withLayerDuration:self.layerDuration];
[shapeLayers addObject:shapeLayer];
[self addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LOTShapeRectangle class]]) {
Expand All @@ -83,7 +83,7 @@ - (void)_setupShapeGroupWithFill:(LOTShapeFill *)previousFill
stroke:currentStroke
trim:currentTrim
transform:currentTransform
withDuration:self.laAnimationDuration];
withLayerDuration:self.layerDuration];
[shapeLayers addObject:shapeLayer];
[self addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LOTShapeCircle class]]) {
Expand All @@ -93,7 +93,7 @@ - (void)_setupShapeGroupWithFill:(LOTShapeFill *)previousFill
stroke:currentStroke
trim:currentTrim
transform:currentTransform
withDuration:self.laAnimationDuration];
withLayerDuration:self.layerDuration];
[shapeLayers addObject:shapeLayer];
[self addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LOTShapeGroup class]]) {
Expand All @@ -103,7 +103,7 @@ - (void)_setupShapeGroupWithFill:(LOTShapeFill *)previousFill
fill:currentFill
stroke:currentStroke
trimPath:currentTrim
withDuration:self.laAnimationDuration];
withLayerDuration:self.layerDuration];
[groupLayers addObject:groupLayer];
[self addSublayer:groupLayer];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

@interface LOTLayerView : LOTAnimatableLayer

- (instancetype)initWithModel:(LOTLayer *)model inComposition:(LOTComposition *)comp;
- (instancetype)initWithModel:(LOTLayer *)model inLayerGroup:(LOTLayerGroup *)layerGroup;

- (void)LOT_addChildLayer:(CALayer *)childLayer;

@property (nonatomic, readonly) LOTLayer *layerModel;
@property (nonatomic, assign) BOOL debugModeOn;
Expand Down
Loading

0 comments on commit bc95f16

Please sign in to comment.