mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
refactor(segment): removing unused code and bringing other code up to date
references #344
This commit is contained in:
@ -57,6 +57,10 @@ export class Segment extends Ion {
|
|||||||
this.buttons = [];
|
this.buttons = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writeValue(value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by child SegmentButtons to bind themselves to
|
* Called by child SegmentButtons to bind themselves to
|
||||||
* the Segment.
|
* the Segment.
|
||||||
@ -97,13 +101,10 @@ export class Segment extends Ion {
|
|||||||
});
|
});
|
||||||
segmentButton.isActive = true;
|
segmentButton.isActive = true;
|
||||||
|
|
||||||
//this.onChange();
|
|
||||||
|
|
||||||
if(!this.ngControl) { return; }
|
if(!this.ngControl) { return; }
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.value = segmentButton.value;
|
this.writeValue(segmentButton.value);
|
||||||
this.ngControl.valueAccessor.writeValue(segmentButton.value);
|
|
||||||
this.selectFromValue(segmentButton.value);
|
this.selectFromValue(segmentButton.value);
|
||||||
|
|
||||||
this.ngControl.control.updateValue(segmentButton.value);
|
this.ngControl.control.updateValue(segmentButton.value);
|
||||||
@ -111,11 +112,6 @@ export class Segment extends Ion {
|
|||||||
// Trigger on change
|
// Trigger on change
|
||||||
this.change.next();
|
this.change.next();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
//this.ngControl.control().updateValue(this.value);
|
|
||||||
// TODO: Better way to do this?
|
|
||||||
//this.controlDirective._control().updateValue(this.value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +120,6 @@ export class Segment extends Ion {
|
|||||||
*/
|
*/
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: 'ion-segment',
|
selector: 'ion-segment',
|
||||||
//inputs: ['value'],
|
|
||||||
host: {
|
host: {
|
||||||
'(change)': 'onChange($event.target.value)',
|
'(change)': 'onChange($event.target.value)',
|
||||||
'(input)': 'onChange($event.target.value)',
|
'(input)': 'onChange($event.target.value)',
|
||||||
@ -157,26 +152,19 @@ export class SegmentControlValueAccessor {
|
|||||||
this.onChange = (_) => {};
|
this.onChange = (_) => {};
|
||||||
this.onTouched = (_) => {};
|
this.onTouched = (_) => {};
|
||||||
|
|
||||||
if(!ngControl) {
|
if(!ngControl) { return; }
|
||||||
// They don't want to do anything that works, so we won't do anything that breaks
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ngControl = ngControl;
|
this.ngControl = ngControl;
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
this.elementRef = elementRef;
|
this.elementRef = elementRef;
|
||||||
this.segment = segment;
|
this.segment = segment;
|
||||||
|
|
||||||
ngControl.valueAccessor = this;
|
this.ngControl.valueAccessor = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value) {
|
writeValue(value) {
|
||||||
// both this.value and setProperty are required at the moment
|
|
||||||
// remove when a proper imperative API is provided
|
|
||||||
this.value = !value ? '' : value;
|
this.value = !value ? '' : value;
|
||||||
|
|
||||||
this.renderer.setElementProperty(this.elementRef, 'value', this.value);
|
|
||||||
|
|
||||||
this.segment.value = this.value;
|
this.segment.value = this.value;
|
||||||
this.segment.selectFromValue(value);
|
this.segment.selectFromValue(value);
|
||||||
}
|
}
|
||||||
@ -229,37 +217,3 @@ export class SegmentButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Android animation similar to tabs
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @private
|
|
||||||
// * TODO
|
|
||||||
// */
|
|
||||||
// @Directive({
|
|
||||||
// selector: 'tab-highlight'
|
|
||||||
// })
|
|
||||||
// class TabHighlight {
|
|
||||||
// constructor(@Host() tabs: Tabs, config: Config, elementRef: ElementRef) {
|
|
||||||
// if (config.get('mode') === 'md') {
|
|
||||||
// tabs.highlight = this;
|
|
||||||
// this.elementRef = elementRef;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// select(tab) {
|
|
||||||
// setTimeout(() => {
|
|
||||||
// let d = tab.btn.getDimensions();
|
|
||||||
// let ele = this.elementRef.nativeElement;
|
|
||||||
// ele.style.transform = 'translate3d(' + d.left + 'px,0,0) scaleX(' + d.width + ')';
|
|
||||||
//
|
|
||||||
// if (!this.init) {
|
|
||||||
// this.init = true;
|
|
||||||
// setTimeout(() => {
|
|
||||||
// ele.classList.add('animate');
|
|
||||||
// }, 64)
|
|
||||||
// }
|
|
||||||
// }, 32);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
Reference in New Issue
Block a user