Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
fix: fix key for svga 1.x format.
Browse files Browse the repository at this point in the history
  • Loading branch information
errnull committed Apr 10, 2019
1 parent 5987e91 commit ec43259
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 60 deletions.
8 changes: 4 additions & 4 deletions SVGAPlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
63712E6521787950001AE014 /* heartbeat.svga in Resources */ = {isa = PBXBuildFile; fileRef = 63712E6421787950001AE014 /* heartbeat.svga */; };
63712E6821787A45001AE014 /* SVGAAudioEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 63712E6721787A45001AE014 /* SVGAAudioEntity.m */; };
63E817012178809D001D2D62 /* SVGAAudioLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E817002178809D001D2D62 /* SVGAAudioLayer.m */; };
71418C712259FAA30029C69E /* mutiMask.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71418C702259FAA30029C69E /* mutiMask.svga */; };
71418C93225E6F710029C69E /* mutiMatte.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71418C92225E6F710029C69E /* mutiMatte.svga */; };
80D4C7254846B96B9C6EED83 /* libPods-SVGAPlayer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DDA5FF396660C7C932DF9B8 /* libPods-SVGAPlayer.a */; };
904D41F81D223DD20085A21A /* SVGABezierPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 904D41F71D223DD20085A21A /* SVGABezierPath.m */; };
9052FC631E6EB8D4007BC925 /* SVGAExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 9052FC621E6EB8D4007BC925 /* SVGAExporter.m */; };
Expand Down Expand Up @@ -64,7 +64,7 @@
63712E6721787A45001AE014 /* SVGAAudioEntity.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAAudioEntity.m; sourceTree = "<group>"; };
63E816FF2178809D001D2D62 /* SVGAAudioLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGAAudioLayer.h; sourceTree = "<group>"; };
63E817002178809D001D2D62 /* SVGAAudioLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAAudioLayer.m; sourceTree = "<group>"; };
71418C702259FAA30029C69E /* mutiMask.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = mutiMask.svga; sourceTree = "<group>"; };
71418C92225E6F710029C69E /* mutiMatte.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = mutiMatte.svga; sourceTree = "<group>"; };
8AD65028FA2D122A34DC4A63 /* Pods-SVGAPlayer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SVGAPlayer.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SVGAPlayer/Pods-SVGAPlayer.debug.xcconfig"; sourceTree = "<group>"; };
904D41F61D223DD20085A21A /* SVGABezierPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGABezierPath.h; sourceTree = "<group>"; };
904D41F71D223DD20085A21A /* SVGABezierPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGABezierPath.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -241,7 +241,7 @@
90D7C9FA1F7E2AA3006E74F0 /* Samples */ = {
isa = PBXGroup;
children = (
71418C702259FAA30029C69E /* mutiMask.svga */,
71418C92225E6F710029C69E /* mutiMatte.svga */,
63712E6421787950001AE014 /* heartbeat.svga */,
90D7CA1A1F7FB114006E74F0 /* rose_1.5.0.svga */,
90D7CA191F7FB114006E74F0 /* rose_2.0.0.svga */,
Expand Down Expand Up @@ -350,11 +350,11 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
71418C93225E6F710029C69E /* mutiMatte.svga in Resources */,
90A676F01D13A6DF008A69F3 /* LaunchScreen.storyboard in Resources */,
90A676ED1D13A6DF008A69F3 /* Assets.xcassets in Resources */,
63712E6521787950001AE014 /* heartbeat.svga in Resources */,
90A676EB1D13A6DF008A69F3 /* Main.storyboard in Resources */,
71418C712259FAA30029C69E /* mutiMask.svga in Resources */,
90CB64F91EF297E800DAA382 /* SVGAPlayer React-Info.plist in Resources */,
90D7CA1C1F7FB114006E74F0 /* rose_1.5.0.svga in Resources */,
90D7CA1B1F7FB114006E74F0 /* rose_2.0.0.svga in Resources */,
Expand Down
25 changes: 22 additions & 3 deletions SVGAPlayer/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="4uQ-1Q-oSI">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="4uQ-1Q-oSI">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -20,7 +20,22 @@
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cmN-DO-oLC" customClass="SVGAPlayer">
<rect key="frame" x="16" y="162" width="343" height="343"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" secondItem="cmN-DO-oLC" secondAttribute="height" multiplier="1:1" id="xm5-jB-e5a"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="cmN-DO-oLC" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="HF3-PL-7Ua"/>
<constraint firstItem="cmN-DO-oLC" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="V4O-Ov-ZmN"/>
<constraint firstItem="cmN-DO-oLC" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="aSq-Gs-nkk"/>
<constraint firstAttribute="trailingMargin" secondItem="cmN-DO-oLC" secondAttribute="trailing" id="vsb-Wl-Nhq"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Samples" id="fYC-8C-nQt">
<barButtonItem key="rightBarButtonItem" title="Change" id="utM-aZ-rcO">
Expand All @@ -29,16 +44,20 @@
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="aPlayer" destination="cmN-DO-oLC" id="9nH-oR-Hmu"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-15" y="36"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="r3U-AC-YtV">
<objects>
<navigationController id="4uQ-1Q-oSI" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="h5y-PJ-oVu">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand Down
Binary file removed SVGAPlayer/Samples/mutiMask.svga
Binary file not shown.
Binary file added SVGAPlayer/Samples/mutiMatte.svga
Binary file not shown.
53 changes: 6 additions & 47 deletions SVGAPlayer/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@interface ViewController ()<SVGAPlayerDelegate>

@property (nonatomic, strong) SVGAPlayer *aPlayer;
@property (weak, nonatomic) IBOutlet SVGAPlayer *aPlayer;

@end

Expand All @@ -22,14 +22,15 @@ @implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];

self.view.backgroundColor = [UIColor blackColor];
[self.view addSubview:self.aPlayer];
self.aPlayer.delegate = self;
self.aPlayer.frame = CGRectMake(0, 0, 320, 320);
self.aPlayer.loops = 0;
self.aPlayer.clearsAfterStop = YES;
parser = [[SVGAParser alloc] init];
[parser parseWithNamed:@"mutiMask"
[self onChange:nil];
}

- (IBAction)onChange:(id)sender {
[parser parseWithNamed:@"mutiMatte"
inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
if (videoItem != nil) {
self.aPlayer.videoItem = videoItem;
Expand All @@ -39,46 +40,4 @@ - (void)viewDidLoad {
}];
}

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.aPlayer.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
}

- (IBAction)onChange:(id)sender {
NSArray *items = @[
@"https://github.com/yyued/SVGA-Samples/blob/master/EmptyState.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/HamburgerArrow.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/PinJump.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/TwitterHeart.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/Walkthrough.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/angel.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/halloween.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/kingset.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/rose.svga?raw=true",
];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[parser parseWithURL:[NSURL URLWithString:items[arc4random() % 10]]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if (videoItem != nil) {
self.aPlayer.videoItem = videoItem;
[self.aPlayer startAnimation];
}
} failureBlock:nil];
// [parser parseWithNamed:@"heartbeat" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
// if (videoItem != nil) {
// self.aPlayer.videoItem = videoItem;
// [self.aPlayer startAnimation];
// }
// } failureBlock:nil];
}

- (SVGAPlayer *)aPlayer {
if (_aPlayer == nil) {
_aPlayer = [[SVGAPlayer alloc] init];
}
return _aPlayer;
}

@end
6 changes: 3 additions & 3 deletions Source/SVGAPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ - (void)draw {
SVGAContentLayer *contentLayer = [sprite requestLayerWithBitmap:bitmap];
contentLayer.imageKey = sprite.imageKey;
tempContentLayers[sprite.imageKey] = contentLayer;
if ([sprite.imageKey hasSuffix:@".mask"]) {
if ([sprite.imageKey hasSuffix:@".matte"]) {
CALayer *hostLayer = [[CALayer alloc] init];
hostLayer.mask = contentLayer;
[self.drawLayer addSublayer:hostLayer];
tempHostLayers[sprite.imageKey] = hostLayer;
} else {
if (sprite.maskImageKey) {
CALayer *hostLayer = tempHostLayers[sprite.maskImageKey];
if (sprite.matteKey && sprite.matteKey.length > 0) {
CALayer *hostLayer = tempHostLayers[sprite.matteKey];
[hostLayer addSublayer:contentLayer];
} else {
[self.drawLayer addSublayer:contentLayer];
Expand Down
2 changes: 1 addition & 1 deletion Source/SVGAVideoSpriteEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@interface SVGAVideoSpriteEntity : NSObject

@property (nonatomic, readonly) NSString *imageKey;
@property (nonatomic, readonly) NSString *maskImageKey;
@property (nonatomic, readonly) NSString *matteKey;
@property (nonatomic, readonly) NSArray<SVGAVideoSpriteFrameEntity *> *frames;

- (instancetype)initWithJSONObject:(NSDictionary *)JSONObject;
Expand Down
4 changes: 2 additions & 2 deletions Source/SVGAVideoSpriteEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject {
if (self) {
if ([JSONObject isKindOfClass:[NSDictionary class]]) {
NSString *imageKey = JSONObject[@"imageKey"];
NSString *maskImageKey = JSONObject[@"maskImageKey"];
NSString *matteKey = JSONObject[@"matteKey"];
NSArray<NSDictionary *> *JSONFrames = JSONObject[@"frames"];
if ([imageKey isKindOfClass:[NSString class]] && [JSONFrames isKindOfClass:[NSArray class]]) {
NSMutableArray<SVGAVideoSpriteFrameEntity *> *frames = [[NSMutableArray alloc] init];
Expand All @@ -29,7 +29,7 @@ - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject {
[frames addObject:[[SVGAVideoSpriteFrameEntity alloc] initWithJSONObject:obj]];
}
}];
_maskImageKey = maskImageKey;
_matteKey = matteKey;
_imageKey = imageKey;
_frames = frames;
}
Expand Down

0 comments on commit ec43259

Please sign in to comment.