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

Commit ec43259

Browse files
committed
fix: fix key for svga 1.x format.
1 parent 5987e91 commit ec43259

8 files changed

Lines changed: 38 additions & 60 deletions

File tree

SVGAPlayer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
63712E6521787950001AE014 /* heartbeat.svga in Resources */ = {isa = PBXBuildFile; fileRef = 63712E6421787950001AE014 /* heartbeat.svga */; };
1212
63712E6821787A45001AE014 /* SVGAAudioEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 63712E6721787A45001AE014 /* SVGAAudioEntity.m */; };
1313
63E817012178809D001D2D62 /* SVGAAudioLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E817002178809D001D2D62 /* SVGAAudioLayer.m */; };
14-
71418C712259FAA30029C69E /* mutiMask.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71418C702259FAA30029C69E /* mutiMask.svga */; };
14+
71418C93225E6F710029C69E /* mutiMatte.svga in Resources */ = {isa = PBXBuildFile; fileRef = 71418C92225E6F710029C69E /* mutiMatte.svga */; };
1515
80D4C7254846B96B9C6EED83 /* libPods-SVGAPlayer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DDA5FF396660C7C932DF9B8 /* libPods-SVGAPlayer.a */; };
1616
904D41F81D223DD20085A21A /* SVGABezierPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 904D41F71D223DD20085A21A /* SVGABezierPath.m */; };
1717
9052FC631E6EB8D4007BC925 /* SVGAExporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 9052FC621E6EB8D4007BC925 /* SVGAExporter.m */; };
@@ -64,7 +64,7 @@
6464
63712E6721787A45001AE014 /* SVGAAudioEntity.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAAudioEntity.m; sourceTree = "<group>"; };
6565
63E816FF2178809D001D2D62 /* SVGAAudioLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGAAudioLayer.h; sourceTree = "<group>"; };
6666
63E817002178809D001D2D62 /* SVGAAudioLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SVGAAudioLayer.m; sourceTree = "<group>"; };
67-
71418C702259FAA30029C69E /* mutiMask.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = mutiMask.svga; sourceTree = "<group>"; };
67+
71418C92225E6F710029C69E /* mutiMatte.svga */ = {isa = PBXFileReference; lastKnownFileType = file; path = mutiMatte.svga; sourceTree = "<group>"; };
6868
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>"; };
6969
904D41F61D223DD20085A21A /* SVGABezierPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGABezierPath.h; sourceTree = "<group>"; };
7070
904D41F71D223DD20085A21A /* SVGABezierPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVGABezierPath.m; sourceTree = "<group>"; };
@@ -241,7 +241,7 @@
241241
90D7C9FA1F7E2AA3006E74F0 /* Samples */ = {
242242
isa = PBXGroup;
243243
children = (
244-
71418C702259FAA30029C69E /* mutiMask.svga */,
244+
71418C92225E6F710029C69E /* mutiMatte.svga */,
245245
63712E6421787950001AE014 /* heartbeat.svga */,
246246
90D7CA1A1F7FB114006E74F0 /* rose_1.5.0.svga */,
247247
90D7CA191F7FB114006E74F0 /* rose_2.0.0.svga */,
@@ -350,11 +350,11 @@
350350
isa = PBXResourcesBuildPhase;
351351
buildActionMask = 2147483647;
352352
files = (
353+
71418C93225E6F710029C69E /* mutiMatte.svga in Resources */,
353354
90A676F01D13A6DF008A69F3 /* LaunchScreen.storyboard in Resources */,
354355
90A676ED1D13A6DF008A69F3 /* Assets.xcassets in Resources */,
355356
63712E6521787950001AE014 /* heartbeat.svga in Resources */,
356357
90A676EB1D13A6DF008A69F3 /* Main.storyboard in Resources */,
357-
71418C712259FAA30029C69E /* mutiMask.svga in Resources */,
358358
90CB64F91EF297E800DAA382 /* SVGAPlayer React-Info.plist in Resources */,
359359
90D7CA1C1F7FB114006E74F0 /* rose_1.5.0.svga in Resources */,
360360
90D7CA1B1F7FB114006E74F0 /* rose_2.0.0.svga in Resources */,

SVGAPlayer/Base.lproj/Main.storyboard

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<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">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<scenes>
@@ -20,7 +20,22 @@
2020
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
2121
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2222
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<subviews>
24+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="cmN-DO-oLC" customClass="SVGAPlayer">
25+
<rect key="frame" x="16" y="162" width="343" height="343"/>
26+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
27+
<constraints>
28+
<constraint firstAttribute="width" secondItem="cmN-DO-oLC" secondAttribute="height" multiplier="1:1" id="xm5-jB-e5a"/>
29+
</constraints>
30+
</view>
31+
</subviews>
2332
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
33+
<constraints>
34+
<constraint firstItem="cmN-DO-oLC" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="HF3-PL-7Ua"/>
35+
<constraint firstItem="cmN-DO-oLC" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="V4O-Ov-ZmN"/>
36+
<constraint firstItem="cmN-DO-oLC" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" id="aSq-Gs-nkk"/>
37+
<constraint firstAttribute="trailingMargin" secondItem="cmN-DO-oLC" secondAttribute="trailing" id="vsb-Wl-Nhq"/>
38+
</constraints>
2439
</view>
2540
<navigationItem key="navigationItem" title="Samples" id="fYC-8C-nQt">
2641
<barButtonItem key="rightBarButtonItem" title="Change" id="utM-aZ-rcO">
@@ -29,16 +44,20 @@
2944
</connections>
3045
</barButtonItem>
3146
</navigationItem>
47+
<connections>
48+
<outlet property="aPlayer" destination="cmN-DO-oLC" id="9nH-oR-Hmu"/>
49+
</connections>
3250
</viewController>
3351
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
3452
</objects>
53+
<point key="canvasLocation" x="-15" y="36"/>
3554
</scene>
3655
<!--Navigation Controller-->
3756
<scene sceneID="r3U-AC-YtV">
3857
<objects>
3958
<navigationController id="4uQ-1Q-oSI" sceneMemberID="viewController">
4059
<navigationBar key="navigationBar" contentMode="scaleToFill" id="h5y-PJ-oVu">
41-
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
60+
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
4261
<autoresizingMask key="autoresizingMask"/>
4362
</navigationBar>
4463
<connections>

SVGAPlayer/Samples/mutiMask.svga

-4.19 KB
Binary file not shown.

SVGAPlayer/Samples/mutiMatte.svga

5.94 KB
Binary file not shown.

SVGAPlayer/ViewController.m

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@interface ViewController ()<SVGAPlayerDelegate>
1313

14-
@property (nonatomic, strong) SVGAPlayer *aPlayer;
14+
@property (weak, nonatomic) IBOutlet SVGAPlayer *aPlayer;
1515

1616
@end
1717

@@ -22,14 +22,15 @@ @implementation ViewController
2222
- (void)viewDidLoad {
2323
[super viewDidLoad];
2424

25-
self.view.backgroundColor = [UIColor blackColor];
26-
[self.view addSubview:self.aPlayer];
2725
self.aPlayer.delegate = self;
28-
self.aPlayer.frame = CGRectMake(0, 0, 320, 320);
2926
self.aPlayer.loops = 0;
3027
self.aPlayer.clearsAfterStop = YES;
3128
parser = [[SVGAParser alloc] init];
32-
[parser parseWithNamed:@"mutiMask"
29+
[self onChange:nil];
30+
}
31+
32+
- (IBAction)onChange:(id)sender {
33+
[parser parseWithNamed:@"mutiMatte"
3334
inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
3435
if (videoItem != nil) {
3536
self.aPlayer.videoItem = videoItem;
@@ -39,46 +40,4 @@ - (void)viewDidLoad {
3940
}];
4041
}
4142

42-
- (void)viewWillLayoutSubviews {
43-
[super viewWillLayoutSubviews];
44-
self.aPlayer.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
45-
}
46-
47-
- (IBAction)onChange:(id)sender {
48-
NSArray *items = @[
49-
@"https://github.com/yyued/SVGA-Samples/blob/master/EmptyState.svga?raw=true",
50-
@"https://github.com/yyued/SVGA-Samples/blob/master/HamburgerArrow.svga?raw=true",
51-
@"https://github.com/yyued/SVGA-Samples/blob/master/PinJump.svga?raw=true",
52-
@"https://github.com/yyued/SVGA-Samples/blob/master/TwitterHeart.svga?raw=true",
53-
@"https://github.com/yyued/SVGA-Samples/blob/master/Walkthrough.svga?raw=true",
54-
@"https://github.com/yyued/SVGA-Samples/blob/master/angel.svga?raw=true",
55-
@"https://github.com/yyued/SVGA-Samples/blob/master/halloween.svga?raw=true",
56-
@"https://github.com/yyued/SVGA-Samples/blob/master/kingset.svga?raw=true",
57-
@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true",
58-
@"https://github.com/yyued/SVGA-Samples/blob/master/rose.svga?raw=true",
59-
];
60-
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
61-
[parser parseWithURL:[NSURL URLWithString:items[arc4random() % 10]]
62-
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
63-
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
64-
if (videoItem != nil) {
65-
self.aPlayer.videoItem = videoItem;
66-
[self.aPlayer startAnimation];
67-
}
68-
} failureBlock:nil];
69-
// [parser parseWithNamed:@"heartbeat" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
70-
// if (videoItem != nil) {
71-
// self.aPlayer.videoItem = videoItem;
72-
// [self.aPlayer startAnimation];
73-
// }
74-
// } failureBlock:nil];
75-
}
76-
77-
- (SVGAPlayer *)aPlayer {
78-
if (_aPlayer == nil) {
79-
_aPlayer = [[SVGAPlayer alloc] init];
80-
}
81-
return _aPlayer;
82-
}
83-
8443
@end

Source/SVGAPlayer.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ - (void)draw {
151151
SVGAContentLayer *contentLayer = [sprite requestLayerWithBitmap:bitmap];
152152
contentLayer.imageKey = sprite.imageKey;
153153
tempContentLayers[sprite.imageKey] = contentLayer;
154-
if ([sprite.imageKey hasSuffix:@".mask"]) {
154+
if ([sprite.imageKey hasSuffix:@".matte"]) {
155155
CALayer *hostLayer = [[CALayer alloc] init];
156156
hostLayer.mask = contentLayer;
157157
[self.drawLayer addSublayer:hostLayer];
158158
tempHostLayers[sprite.imageKey] = hostLayer;
159159
} else {
160-
if (sprite.maskImageKey) {
161-
CALayer *hostLayer = tempHostLayers[sprite.maskImageKey];
160+
if (sprite.matteKey && sprite.matteKey.length > 0) {
161+
CALayer *hostLayer = tempHostLayers[sprite.matteKey];
162162
[hostLayer addSublayer:contentLayer];
163163
} else {
164164
[self.drawLayer addSublayer:contentLayer];

Source/SVGAVideoSpriteEntity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@interface SVGAVideoSpriteEntity : NSObject
1616

1717
@property (nonatomic, readonly) NSString *imageKey;
18-
@property (nonatomic, readonly) NSString *maskImageKey;
18+
@property (nonatomic, readonly) NSString *matteKey;
1919
@property (nonatomic, readonly) NSArray<SVGAVideoSpriteFrameEntity *> *frames;
2020

2121
- (instancetype)initWithJSONObject:(NSDictionary *)JSONObject;

Source/SVGAVideoSpriteEntity.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject {
2020
if (self) {
2121
if ([JSONObject isKindOfClass:[NSDictionary class]]) {
2222
NSString *imageKey = JSONObject[@"imageKey"];
23-
NSString *maskImageKey = JSONObject[@"maskImageKey"];
23+
NSString *matteKey = JSONObject[@"matteKey"];
2424
NSArray<NSDictionary *> *JSONFrames = JSONObject[@"frames"];
2525
if ([imageKey isKindOfClass:[NSString class]] && [JSONFrames isKindOfClass:[NSArray class]]) {
2626
NSMutableArray<SVGAVideoSpriteFrameEntity *> *frames = [[NSMutableArray alloc] init];
@@ -29,7 +29,7 @@ - (instancetype)initWithJSONObject:(NSDictionary *)JSONObject {
2929
[frames addObject:[[SVGAVideoSpriteFrameEntity alloc] initWithJSONObject:obj]];
3030
}
3131
}];
32-
_maskImageKey = maskImageKey;
32+
_matteKey = matteKey;
3333
_imageKey = imageKey;
3434
_frames = frames;
3535
}

0 commit comments

Comments
 (0)