UNPKG

rax-image

Version:
82 lines (81 loc) 1.92 kB
import fmtEvent from './fmtEvent'; Component({ data: { style: '' }, properties: { className: { type: String, value: '' }, styleSheet: { type: String, value: '' }, mode: { type: String, value: 'scaleToFill' }, src: { type: String, value: '' }, source: { type: Object, value: { uri: '' } }, loading: { type: String, value: 'eager' }, lazyLoad: { type: Boolean, value: false } }, lifetimes: { attached: function attached() { this.initImage(); } }, observers: { styleSheet: function styleSheet(newStyleSheet) { this.initImage('styleSheet', newStyleSheet); }, source: function source(newSource) { this.initImage('source', newSource); } }, options: { styleIsolation: 'apply-shared' }, methods: { onError: function onError(e) { var event = fmtEvent(this.properties, e); this.triggerEvent('onError', event.detail); }, onLoad: function onLoad(e) { var event = fmtEvent(this.properties, e); this.triggerEvent('onLoad', event.detail); }, onTap: function onTap(e) { var event = fmtEvent(this.properties, e); this.triggerEvent('onClick', event.detail); }, initImage: function initImage(type, newValue) { var _ref = type === 'source' ? newValue : this.properties.source || {}, _ref$width = _ref.width, width = _ref$width === void 0 ? null : _ref$width, _ref$height = _ref.height, height = _ref$height === void 0 ? null : _ref$height; var style = type === 'styleSheet' ? newValue : this.properties.styleSheet || ''; if (width) style += 'width:' + width + 'rpx;'; if (height) style += 'height:' + height + 'rpx;'; this.setData({ style: style }); } } });