提交 54fb8dc9 编写于 作者: D DCloud_LXH

fix(nvue): movable-view、picker-view

上级 fdb017c6
export const props = {
nodes: {
type: [Array, String],
default: function () {
return []
},
},
}
...@@ -4,6 +4,9 @@ import Button from './button' ...@@ -4,6 +4,9 @@ import Button from './button'
import MovableArea from './movable-area' import MovableArea from './movable-area'
import MovableView from './movable-view' import MovableView from './movable-view'
import Progress from './progress' import Progress from './progress'
import PickerView from './picker-view'
import PickerViewColumn from './picker-view-column'
import Picker from './picker'
export default { export default {
Navigator, Navigator,
Label, Label,
...@@ -11,4 +14,7 @@ export default { ...@@ -11,4 +14,7 @@ export default {
MovableArea, MovableArea,
MovableView, MovableView,
Progress, Progress,
PickerView,
PickerViewColumn,
Picker,
} }
...@@ -32,8 +32,7 @@ export default defineComponent({ ...@@ -32,8 +32,7 @@ export default defineComponent({
styles: [ styles: [
{ {
'uni-movable-area': { 'uni-movable-area': {
width: '10px', '': { width: '10px', height: '10px' },
height: '10px',
}, },
}, },
], ],
......
...@@ -113,11 +113,13 @@ export default defineComponent({ ...@@ -113,11 +113,13 @@ export default defineComponent({
styles: [ styles: [
{ {
'uni-movable-view': { 'uni-movable-view': {
position: 'absolute', '': {
top: '0px', position: 'absolute',
left: '0px', top: '0px',
width: '10px', left: '0px',
height: '10px', width: '10px',
height: '10px',
},
}, },
}, },
], ],
......
...@@ -47,18 +47,19 @@ export default defineComponent({ ...@@ -47,18 +47,19 @@ export default defineComponent({
const indicatorRef: Ref<HTMLElement | null> = ref(null) const indicatorRef: Ref<HTMLElement | null> = ref(null)
const pickerViewProps = inject<Props>('pickerViewProps')! const pickerViewProps = inject<Props>('pickerViewProps')!
const getPickerViewColumn = inject<GetPickerViewColumn>( const getPickerViewColumn = inject(
'getPickerViewColumn', 'getPickerViewColumn'
() => computed({ set: () => {}, get: () => 0 }) ) as GetPickerViewColumn
)
const current = getPickerViewColumn(instance) const current = getPickerViewColumn(instance)
const indicatorStyle = computed(() => const indicatorStyle = computed(() =>
getStyle(pickerViewProps.indicatorStyle) getStyle(pickerViewProps.indicatorStyle)
) )
const maskStyle = computed(() => getStyle(pickerViewProps.maskStyle)) const maskStyle = computed(() => getStyle(pickerViewProps.maskStyle))
let indicatorHeight = getHeight(indicatorStyle) let indicatorHeight = ref(0)
let pickerViewHeight = parseFloat(pickerViewProps.height as string) indicatorHeight.value = getHeight(indicatorStyle.value)
let pickerViewHeight = ref(0)
pickerViewHeight.value = parseFloat(pickerViewProps.height as string)
watch( watch(
() => props.length, () => props.length,
...@@ -75,7 +76,7 @@ export default defineComponent({ ...@@ -75,7 +76,7 @@ export default defineComponent({
return return
} }
dom.scrollToElement(contentRef.value, { dom.scrollToElement(contentRef.value, {
offset: _current * indicatorHeight, offset: _current * indicatorHeight.value,
animated, animated,
}) })
current.value = _current current.value = _current
...@@ -83,13 +84,15 @@ export default defineComponent({ ...@@ -83,13 +84,15 @@ export default defineComponent({
scrollToElementTime = Date.now() scrollToElementTime = Date.now()
} }
} }
const onScrollend = (event: { detail: Record<string, any> }) => { const onScrollend = (event: {
contentOffset: { x: number; y: number }
}) => {
if (Date.now() - scrollToElementTime < 340) { if (Date.now() - scrollToElementTime < 340) {
return return
} }
const y = event.detail.contentOffset.y const y = event.contentOffset.y
const _current = Math.round(y / indicatorHeight) const _current = Math.round(y / indicatorHeight.value)
if (y % indicatorHeight) { if (y % indicatorHeight.value) {
setCurrent(_current, true, true) setCurrent(_current, true, true)
} else { } else {
current.value = _current current.value = _current
...@@ -101,15 +104,15 @@ export default defineComponent({ ...@@ -101,15 +104,15 @@ export default defineComponent({
setTimeout(() => { setTimeout(() => {
Promise.all([ Promise.all([
getComponentSize(rootRef.value!).then(({ height }) => { getComponentSize(rootRef.value!).then(({ height }) => {
height_ = pickerViewHeight = height height_ = pickerViewHeight.value = height
}), }),
isAndroid && props.length isAndroid && props.length
? getComponentSize(scrollViewItemRef.value!).then(({ height }) => { ? getComponentSize(scrollViewItemRef.value!).then(({ height }) => {
indicatorHeight_ = indicatorHeight = indicatorHeight_ = indicatorHeight.value =
height / parseFloat(props.length as string) height / parseFloat(props.length as string)
}) })
: getComponentSize(indicatorRef.value!).then(({ height }) => { : getComponentSize(indicatorRef.value!).then(({ height }) => {
indicatorHeight_ = indicatorHeight = height indicatorHeight_ = indicatorHeight.value = height
}), }),
]).then(() => { ]).then(() => {
if (height_ && indicatorHeight_) { if (height_ && indicatorHeight_) {
...@@ -140,8 +143,8 @@ export default defineComponent({ ...@@ -140,8 +143,8 @@ export default defineComponent({
return () => { return () => {
const children = slots.default && slots.default() const children = slots.default && slots.default()
let padding = (pickerViewHeight - indicatorHeight) / 2 let padding = (pickerViewHeight.value - indicatorHeight.value) / 2
const maskPosition = `${pickerViewHeight - padding}px` const maskPosition = `${pickerViewHeight.value - padding}px`
const scrollOptions: ScrollOptions = { const scrollOptions: ScrollOptions = {
showScrollbar: false, showScrollbar: false,
scrollToBegin: false, scrollToBegin: false,
...@@ -149,7 +152,7 @@ export default defineComponent({ ...@@ -149,7 +152,7 @@ export default defineComponent({
scrollY: true, scrollY: true,
} }
if (!isAndroid) { if (!isAndroid) {
scrollOptions.scrollTop = current.value * indicatorHeight scrollOptions.scrollTop = current.value * indicatorHeight.value
} }
return ( return (
...@@ -172,7 +175,7 @@ export default defineComponent({ ...@@ -172,7 +175,7 @@ export default defineComponent({
{createScrollViewChild(children)} {createScrollViewChild(children)}
</view> </view>
</scroll-view> </scroll-view>
<u-scalable class="uni-picker-view-mask" style={maskStyle}> <u-scalable class="uni-picker-view-mask" style={maskStyle.value}>
<u-scalable <u-scalable
class="uni-picker-view-mask uni-picker-view-mask-top" class="uni-picker-view-mask uni-picker-view-mask-top"
style={{ style={{
...@@ -200,52 +203,60 @@ export default defineComponent({ ...@@ -200,52 +203,60 @@ export default defineComponent({
styles: [ styles: [
{ {
'uni-picker-view-column': { 'uni-picker-view-column': {
flex: 1, '': {
position: 'relative', flex: 1,
alignItems: 'stretch', position: 'relative',
overflow: 'hidden', alignItems: 'stretch',
overflow: 'hidden',
},
}, },
'uni-picker-view-mask': { 'uni-picker-view-mask': {
position: 'absolute', '': {
top: 0, position: 'absolute',
left: 0, top: 0,
right: 0, left: 0,
bottom: 0, right: 0,
pointerEvents: 'none', bottom: 0,
pointerEvents: 'none',
},
}, },
'uni-picker-view-mask-top': { 'uni-picker-view-mask-top': {
bottom: 0, '': {
backgroundImage: bottom: 0,
'linear-gradient(to bottom,rgba(255, 255, 255, 0.95),rgba(255, 255, 255, 0.6))', backgroundImage:
'linear-gradient(to bottom,rgba(255, 255, 255, 0.95),rgba(255, 255, 255, 0.6))',
},
}, },
'uni-picker-view-mask-bottom': { 'uni-picker-view-mask-bottom': {
top: 0, '': {
backgroundImage: top: 0,
'linear-gradient(to top,rgba(255, 255, 255, 0.95),rgba(255, 255, 255, 0.6))', backgroundImage:
'linear-gradient(to top,rgba(255, 255, 255, 0.95),rgba(255, 255, 255, 0.6))',
},
}, },
'uni-picker-view-group': { 'uni-picker-view-group': {
position: 'absolute', '': { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 },
top: 0,
left: 0,
right: 0,
bottom: 0,
}, },
'uni-picker-view-content': { 'uni-picker-view-content': {
paddingTop: 0, '': {
paddingRight: 0, paddingTop: 0,
paddingBottom: 0, paddingRight: 0,
paddingLeft: 0, paddingBottom: 0,
paddingLeft: 0,
},
}, },
'uni-picker-view-indicator': { 'uni-picker-view-indicator': {
position: 'absolute', '': {
left: 0, position: 'absolute',
right: 0, left: 0,
top: 0, right: 0,
height: '34px', top: 0,
pointerEvents: 'none', height: '34px',
borderColor: '#e5e5e5', pointerEvents: 'none',
borderTopWidth: '1px', borderColor: '#e5e5e5',
borderBottomWidth: '1px', borderTopWidth: '1px',
borderBottomWidth: '1px',
},
}, },
}, },
], ],
......
...@@ -17,7 +17,7 @@ import { ...@@ -17,7 +17,7 @@ import {
import { flatVNode } from '../../helpers/flatVNode' import { flatVNode } from '../../helpers/flatVNode'
import { useCustomEvent, EmitEvent } from '../../helpers/useNVueEvent' import { useCustomEvent, EmitEvent } from '../../helpers/useNVueEvent'
export { Props, GetPickerViewColumn } export type { Props, GetPickerViewColumn }
const nvuePickerViewProps = extend({}, pickerViewProps, { const nvuePickerViewProps = extend({}, pickerViewProps, {
height: { height: {
type: [Number, String], type: [Number, String],
...@@ -36,7 +36,7 @@ export default defineComponent({ ...@@ -36,7 +36,7 @@ export default defineComponent({
let columnVNodes: VNode[] = [] let columnVNodes: VNode[] = []
const getItemIndex = (vnode: VNode) => const getItemIndex = (vnode: VNode) =>
Array.prototype.indexOf.call(columnVNodes, vnode.el) Array.prototype.indexOf.call(columnVNodes, vnode)
const getPickerViewColumn: GetPickerViewColumn = (columnInstance) => { const getPickerViewColumn: GetPickerViewColumn = (columnInstance) => {
return computed({ return computed({
get() { get() {
...@@ -85,17 +85,19 @@ export default defineComponent({ ...@@ -85,17 +85,19 @@ export default defineComponent({
styles: [ styles: [
{ {
'uni-picker-view': { 'uni-picker-view': {
position: 'relative', '': { position: 'relative' },
}, },
'uni-picker-view-wrapper': { 'uni-picker-view-wrapper': {
display: 'flex', '': {
flexDirection: 'row', display: 'flex',
position: 'absolute', flexDirection: 'row',
top: 0, position: 'absolute',
left: 0, top: 0,
right: 0, left: 0,
bottom: 0, right: 0,
overflow: 'hidden', bottom: 0,
overflow: 'hidden',
},
}, },
}, },
], ],
......
...@@ -6,15 +6,7 @@ import { ...@@ -6,15 +6,7 @@ import {
} from '@dcloudio/uni-components' } from '@dcloudio/uni-components'
import parseHtml from './html-parser' import parseHtml from './html-parser'
import parseNodes from './nodes-parser' import parseNodes from './nodes-parser'
import { props } from '../../components/rich-text'
const props = {
nodes: {
type: [Array, String],
default: function () {
return []
},
},
}
export default /*#__PURE__*/ defineBuiltInComponent({ export default /*#__PURE__*/ defineBuiltInComponent({
name: 'RichText', name: 'RichText',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册