mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
adding slider control
This commit is contained in:
@@ -279,6 +279,10 @@
|
||||
<TypeScriptCompile Include="ui\button\button.ios.ts">
|
||||
<DependentUpon>button.d.ts</DependentUpon>
|
||||
</TypeScriptCompile>
|
||||
<TypeScriptCompile Include="ui\slider\index.ts" />
|
||||
<TypeScriptCompile Include="ui\slider\slider.android.ts" />
|
||||
<TypeScriptCompile Include="ui\slider\slider.d.ts" />
|
||||
<TypeScriptCompile Include="ui\slider\slider.ios.ts" />
|
||||
<Content Include="_references.ts" />
|
||||
<Content Include="image-source\Readme.md" />
|
||||
<Content Include="http\Readme.md" />
|
||||
|
||||
2
ui/slider/index.ts
Normal file
2
ui/slider/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
declare var module, require;
|
||||
module.exports = require("ui/slider/slider");
|
||||
88
ui/slider/slider.android.ts
Normal file
88
ui/slider/slider.android.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
import observable = require("ui/core/observable");
|
||||
import view = require("ui/core/view");
|
||||
import application = require("application");
|
||||
|
||||
export class Slider extends view.View {
|
||||
private static valueProperty = "value";
|
||||
private static maxValueProperty = "maxValue";
|
||||
|
||||
private _android: android.widget.SeekBar;
|
||||
private _changeListener: android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
|
||||
private _preValue: number;
|
||||
private _preMaxValue: number;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._preValue = 0;
|
||||
this._preMaxValue = 100;
|
||||
}
|
||||
|
||||
private createUI(context: android.content.Context) {
|
||||
this._android = new android.widget.SeekBar(context);
|
||||
|
||||
this._android.setMax(this._preMaxValue);
|
||||
this._android.setProgress(this._preValue);
|
||||
|
||||
var that = this;
|
||||
this._changeListener = new android.widget.SeekBar.OnSeekBarChangeListener({
|
||||
onProgressChanged: function (seekBar: android.widget.SeekBar, progress: number, fromUser: boolean) {
|
||||
//console.log("changed");
|
||||
that.setProperty(Slider.valueProperty, seekBar.getProgress());
|
||||
},
|
||||
|
||||
onStartTrackingTouch: function (seekBar: android.widget.SeekBar) {
|
||||
|
||||
},
|
||||
|
||||
onStopTrackingTouch: function (seekBar: android.widget.SeekBar) {
|
||||
|
||||
}
|
||||
});
|
||||
this._android.setOnSeekBarChangeListener(this._changeListener);
|
||||
}
|
||||
|
||||
public onInitialized(context: android.content.Context) {
|
||||
if (!this._android) {
|
||||
// TODO: We need to decide whether we will support context switching and if yes - to implement it.
|
||||
this.createUI(context);
|
||||
}
|
||||
}
|
||||
|
||||
get android(): android.widget.SeekBar {
|
||||
return this._android;
|
||||
}
|
||||
|
||||
get maxValue(): number {
|
||||
return this._android.getMax();
|
||||
}
|
||||
|
||||
set maxValue(value: number) {
|
||||
this.setProperty(Slider.maxValueProperty, value);
|
||||
}
|
||||
|
||||
get value(): number {
|
||||
return this._android.getProgress();
|
||||
}
|
||||
|
||||
set value(value: number) {
|
||||
this.setProperty(Slider.valueProperty, value);
|
||||
}
|
||||
|
||||
public setNativeProperty(data: observable.PropertyChangeData) {
|
||||
// TODO: Will this be a gigantic if-else switch?
|
||||
if (data.propertyName === Slider.maxValueProperty) {
|
||||
if (this._android)
|
||||
this._android.setMax(data.value);
|
||||
else
|
||||
this._preMaxValue = data.value;
|
||||
} else if (data.propertyName === Slider.valueProperty) {
|
||||
if (this._android)
|
||||
this._android.setProgress(data.value);
|
||||
else
|
||||
this._preValue = data.value;
|
||||
} else if (true) {
|
||||
}
|
||||
}
|
||||
}
|
||||
10
ui/slider/slider.d.ts
vendored
Normal file
10
ui/slider/slider.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
declare module "ui/slider" {
|
||||
|
||||
class Slider {
|
||||
android: android.widget.SeekBar;
|
||||
ios: UIKit.UISlider;
|
||||
|
||||
value: number;
|
||||
maxValue: number;
|
||||
}
|
||||
}
|
||||
63
ui/slider/slider.ios.ts
Normal file
63
ui/slider/slider.ios.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
import observable = require("ui/core/observable");
|
||||
import view = require("ui/core/view");
|
||||
|
||||
export class Slider extends view.View {
|
||||
private static valueProperty = "value";
|
||||
private static maxValueProperty = "maxValue";
|
||||
private _ios: UIKit.UISlider;
|
||||
private changeHandler: Foundation.NSObject;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._ios = new UIKit.UISlider();
|
||||
|
||||
// default values
|
||||
this._ios.minimumValue = 0;
|
||||
this._ios.maximumValue = 100;
|
||||
|
||||
var that = this;
|
||||
var ChangeHandler = Foundation.NSObject.extends(
|
||||
{
|
||||
sliderValueChanged: function (sender: UIKit.UISlider) {
|
||||
that.setProperty(Slider.valueProperty, sender.value);
|
||||
}
|
||||
}, {
|
||||
exposedMethods: {
|
||||
'sliderValueChanged': 'v@:@'
|
||||
}
|
||||
});
|
||||
|
||||
this.changeHandler = new ChangeHandler();
|
||||
this._ios.addTargetActionForControlEvents(this.changeHandler, "sliderValueChanged", UIKit.UIControlEvents.UIControlEventValueChanged);
|
||||
}
|
||||
|
||||
get ios(): UIKit.UISlider {
|
||||
return this._ios;
|
||||
}
|
||||
|
||||
get maxValue(): number {
|
||||
return this._ios.maximumValue;
|
||||
}
|
||||
|
||||
set maxValue(value: number) {
|
||||
this.setProperty(Slider.maxValueProperty, value);
|
||||
}
|
||||
|
||||
get value(): number {
|
||||
return this._ios.value;
|
||||
}
|
||||
|
||||
set value(value: number) {
|
||||
this.setProperty(Slider.valueProperty, value);
|
||||
}
|
||||
|
||||
public setNativeProperty(data: observable.PropertyChangeData) {
|
||||
if (data.propertyName === Slider.maxValueProperty) {
|
||||
this._ios.maximumValue = data.value;
|
||||
} else if (data.propertyName === Slider.valueProperty) {
|
||||
this._ios.value = data.value;
|
||||
} else if (true) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user