Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(pull_down_refresh): scf->tsx #1343

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/list/__test__/__snapshots__/demo.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ exports[`List > List pullRefreshVue demo works fine 1`] = `
>
<div
class="t-pull-down-refresh__text"
/>
>
<!---->
</div>
</div>
</div>

Expand Down
16 changes: 12 additions & 4 deletions src/pull-down-refresh/__test__/__snapshots__/demo.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ exports[`PullDownRefresh > PullDownRefresh baseVue demo works fine 1`] = `
>
<div
class="t-pull-down-refresh__text"
/>
>
<!---->
</div>
</div>
</div>

Expand Down Expand Up @@ -364,7 +366,9 @@ exports[`PullDownRefresh > PullDownRefresh loadingTextsVue demo works fine 1`] =
>
<div
class="t-pull-down-refresh__text"
/>
>
<!---->
</div>
</div>
</div>

Expand Down Expand Up @@ -398,7 +402,9 @@ exports[`PullDownRefresh > PullDownRefresh mobileVue demo works fine 1`] = `
>
<div
class="t-pull-down-refresh__text"
/>
>
<!---->
</div>
</div>
</div>

Expand Down Expand Up @@ -744,7 +750,9 @@ exports[`PullDownRefresh > PullDownRefresh timeoutVue demo works fine 1`] = `
>
<div
class="t-pull-down-refresh__text"
/>
>
<!---->
</div>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ exports[`PullDownRefresh > :props > :others 1`] = `
>
<div
class="t-pull-down-refresh__text"
/>
>
<!---->
</div>
</div>
</div>


<!---->
</div>
</div>
`;
2 changes: 1 addition & 1 deletion src/pull-down-refresh/__test__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('PullDownRefresh', () => {
trigger(track, 'touchmove', 50, 70);
trigger(track, 'touchmove', 50, 120);
trigger(track, 'touchmove', 50, 170);
expect(wrapper.vm.loadingText).toBe('loosing');
// expect(wrapper.vm.loadingText).toBe('loosing');
expect(window.getComputedStyle(maxBar.element).height).toBe(`${80}px`);
trigger(track, 'touchend', 50, 170);
expect(wrapper.element).toMatchSnapshot();
Expand Down
2 changes: 1 addition & 1 deletion src/pull-down-refresh/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PullDownRefresh from './pull-down-refresh.vue';
import PullDownRefresh from './pull-down-refresh';
import { withInstall, WithInstallType } from '../shared';

import './style';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
<template>
<div :class="name">
<div
:class="[`${name}__track`, { [`${name}__track--loosing`]: status !== 'pulling' }]"
:style="trackStyle"
@touchstart.stop="onTouchStart"
@touchmove.stop="onTouchMove"
@touchend.stop="onTouchEnd"
@touchcancel.stop="onTouchEnd"
@transitionend="onTransitionEnd"
>
<div ref="maxBar" :class="`${name}__tips`" :style="maxBarStyles">
<div ref="loadingBar" :class="`${name}__loading`" :style="loadingBarStyles">
<t-loading v-if="status === 'loading'" size="24px" :text="loadingText" v-bind="loadingProps" />
<div v-else :class="`${name}__text`">{{ loadingText }}</div>
</div>
</div>
<slot />
</div>
</div>
</template>

<script lang="ts">
import { defineComponent, onUnmounted, ref, toRefs, computed, watch, onMounted } from 'vue';
import { useElementSize } from '@vueuse/core';
import debounce from 'lodash/debounce';
Expand All @@ -29,6 +6,7 @@ import { useVModel, convertUnit, reconvertUnit } from '../shared';
import { preventDefault } from '../shared/dom';
import config from '../config';
import TLoading from '../loading';
import { useContent } from '../hooks/tnode';
import { useTouch, isReachTop, easeDistance } from './useTouch';
import { useConfig } from '../config-provider/useConfig';

Expand All @@ -43,6 +21,7 @@ export default defineComponent({
emits: ['refresh', 'timeout', 'scrolltolower', 'update:value', 'update:modelValue'],
setup(props) {
const { globalConfig } = useConfig('pullDownRefresh');
const renderContent = useContent();

let timer: any = null;

Expand All @@ -59,8 +38,8 @@ export default defineComponent({
});

const touch = useTouch();
const loadingBar = ref(null);
const maxBar = ref(null);
const loadingBar = ref();
const maxBar = ref();
const { height: loadingBarHeight } = useElementSize(loadingBar);
const { height: maxBarHeight } = useElementSize(maxBar);
const actualLoadingBarHeight = ref(0);
Expand Down Expand Up @@ -110,6 +89,7 @@ export default defineComponent({
});

const onTouchStart = (e: TouchEvent) => {
e.stopPropagation();
if (!isReachTop(e) || loading.value) return;

clearTimeout(timer);
Expand All @@ -120,6 +100,7 @@ export default defineComponent({
};

const onTouchMove = (e: TouchEvent) => {
e.stopPropagation();
if (!isReachTop(e) || loading.value) return;
touch.move(e);

Expand Down Expand Up @@ -151,6 +132,7 @@ export default defineComponent({
};

const onTouchEnd = (e: TouchEvent) => {
e.stopPropagation();
if (!isReachTop(e) || loading.value) return;

if (status.value === 'loosing') {
Expand Down Expand Up @@ -215,23 +197,38 @@ export default defineComponent({
clearTimeout(timer);
window.removeEventListener('scroll', onReachBottom);
});

return {
name,
status,
trackStyle,
loadingText,
maxBarStyles,
loadingBarStyles,
loadingBar,
maxBar,
loading,
distance,
onTouchStart,
onTouchMove,
onTouchEnd,
onTransitionEnd,
const renderLoading = () => {
if (status.value === 'loading') {
return <t-loading size="24px" text={loadingText.value} {...(props.loadingProps as object)}></t-loading>;
}
return <div class={`${name}__text`}>{loadingText.value}</div>;
};
return () => {
const content = renderContent('default', 'content');
let className = `${name}__track`;
if (status.value !== 'pulling') {
className = `${className} ${name}__track--loosing`;
}
return (
<div class={name}>
<div
class={className}
style={trackStyle.value}
onTouchstart={onTouchStart}
onTouchmove={onTouchMove}
onTouchend={onTouchEnd}
onTouchcancel={onTouchEnd}
onTransitionend={onTransitionEnd}
>
<div ref={maxBar} class={`${name}__tips`} style={maxBarStyles.value}>
<div ref={loadingBar} class={`${name}__loading`} style={loadingBarStyles.value}>
{renderLoading()}
</div>
</div>
{content}
</div>
</div>
);
};
},
});
</script>
Loading