Skip to content

Commit 8b0aefd

Browse files
committed
adjust size to scale on ios
1 parent 9826d7b commit 8b0aefd

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/nativescript-lottie.ios.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
**********************************************************************************/
77
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
88

9-
import { View, layout } from 'tns-core-modules/ui/core/view';
10-
import { Property } from 'tns-core-modules/ui/core/properties';
11-
import { topmost } from 'tns-core-modules/ui/frame/frame';
9+
import { layout } from 'tns-core-modules/ui/core/view';
1210
import { LottieViewBase, srcProperty, loopProperty, autoPlayProperty } from './nativescript-lottie.common';
13-
11+
import { screen } from 'tns-core-modules/platform';
1412
declare var LOTAnimationView: any;
1513

1614
export class LottieView extends LottieViewBase {
@@ -37,14 +35,18 @@ export class LottieView extends LottieViewBase {
3735
}
3836

3937
private createAnimationView(src: string) {
38+
if (!this.getMeasuredHeight()) {
39+
setTimeout(() => this.createAnimationView(src), 50);
40+
return;
41+
}
42+
4043
this._animationView = LOTAnimationView.animationNamed(src);
4144
this.contentModeDefault();
4245
this.ios.addSubview(this._animationView);
4346

44-
const newFrameHeight =
45-
typeof this.height === 'number' ? this.height : this.getMeasuredHeight() > 0 ? this.getMeasuredHeight() / 2 : 150;
46-
const newFrameWidth =
47-
typeof this.width === 'number' ? this.width : this.getMeasuredWidth() > 0 ? this.getMeasuredWidth() / 3 : 150;
47+
const scale = screen.mainScreen.scale;
48+
const newFrameHeight = this.getMeasuredHeight() / scale;
49+
const newFrameWidth = this.getMeasuredWidth() / scale;
4850

4951
const newFrame = CGRectMake(0, 0, newFrameWidth, newFrameHeight);
5052

@@ -96,8 +98,10 @@ export class LottieView extends LottieViewBase {
9698
if (nativeView) {
9799
const measuredWidth = layout.getMeasureSpecSize(widthMeasureSpec);
98100
const measuredHeight = layout.getMeasureSpecSize(heightMeasureSpec);
99-
const width = typeof this.width === 'number' ? this.width : measuredWidth / 3;
100-
const height = typeof this.height === 'number' ? this.height : measuredHeight / 2;
101+
102+
const scale = screen.mainScreen.scale;
103+
const width = typeof this.width === 'number' ? this.width : measuredWidth / scale;
104+
const height = typeof this.height === 'number' ? this.height : measuredHeight / scale;
101105
this.setMeasuredDimension(measuredWidth, measuredHeight);
102106
if (this._animationView) {
103107
const newFrame = CGRectMake(0, 0, width, height);

0 commit comments

Comments
 (0)