forked from triniwiz/nativescript-star-ratings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstar-ratings.ios.ts
executable file
·91 lines (68 loc) · 2.56 KB
/
star-ratings.ios.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { ContentView } from 'ui/content-view';
import { Color } from 'color';
import * as imageSource from 'image-source';
declare var UIView, UIColor, UIImage, UIControlEvents, CGRectMake, WeakRef, interop;
declare var HCSStarRatingView: any;
export class StarRating extends ContentView {
private _ios: any;
private _view: any;
// private _changeHandler: StarRatingChangeHandlerImpl;
width: number = 100;
height: number = 25;
allowsHalfStars: boolean = false;
accurateHalfStars: boolean = true;
max: number = 10;
min: number = 0;
value: number = 0;
emptyStar: string = 'heart-empty';
halfStar: string = 'heart-half';
filledStar: string = 'heart-full';
constructor() {
super();
this._view = UIView.new();
}
get ios(): any {
return this._ios;
}
get _nativeView(): any {
return this._view;
}
onLoaded() {
super.onLoaded();
this._ios = HCSStarRatingView.alloc().initWithFrame(CGRectMake(0, 0, this.width, this.height));
this._ios.maximumValue = this.max;
this._ios.minimumValue = this.min;
this._ios.value = this.value;
this._ios.allowsHalfStars = this.allowsHalfStars;
this._ios.accurateHalfStars = this.accurateHalfStars;
this._ios.emptyStarImage = imageSource.fromResource(this.emptyStar);
this._ios.filledStarImage = imageSource.fromResource(this.filledStar);
if(this.halfStar) {
this._ios.halfStarImage = imageSource.fromResource(this.halfStar);
}
// this._changeHandler = StarRatingChangeHandlerImpl.initWithOwner(new WeakRef(this));
// this._ios.addTargetActionForControlEvents(this._changeHandler, 'didChangeValue', UIControlEvents.ValueChanged);
this._view.addSubview(this._ios);
}
set starColor(tintColor: any) {
this._ios.tintColor = tintColor.ios;
}
}
// class StarRatingChangeHandlerImpl extends NSObject {
// private _owner: WeakRef<StarRating>;
// public static initWithOwner(owner: WeakRef<StarRating>): StarRatingChangeHandlerImpl {
// let handler = <StarRatingChangeHandlerImpl> StarRatingChangeHandlerImpl.new();
// handler._owner = owner;
// return handler;
// }
// public didChangeValue(sender: any) {
// let owner = this._owner.get();
// if(!owner) {
// return;
// }
// owner.didChangeValue(sender);
// }
// public static ObjCExposedMethods = {
// 'didChangeValue': { returns: interop.types.void, params: [] }
// }
// }