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

fix(base-loading): revert to the old code & make animation work with blocking method & fix fur in animation #5072

Merged
merged 6 commits into from
Dec 20, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- 修复 `n-radio` value 值取消更新后,input 原生 checked 值未更新,关闭 [#5184](https://github.com/tusen-ai/naive-ui/issues/5184)
- Fix `n-data-table` height incorrect when set `min-height` in empty state,closes [#5108](https://github.com/tusen-ai/naive-ui/issues/5108).
- Fix `n-tabs`'s bar not hidden when `value` is set manually to the value other than the children `n-tab`s, closes [#5100](https://github.com/tusen-ai/naive-ui/issues/5100).
- Fix `n-spin` abnormal animation,closes [#3556](https://github.com/tusen-ai/naive-ui/issues/3556)

### Features

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- 修复 `n-radio` value 值取消更新后,input 原生 checked 值未更新,关闭 [#5184](https://github.com/tusen-ai/naive-ui/issues/5184)
- 修复 `n-data-table` 空表格在设置 `min-height` 时高度不正确,关闭 [#5108](https://github.com/tusen-ai/naive-ui/issues/5108)
- Fix `n-tabs`'s bar not hidden when `value` is set manually to the value other than the children `n-tab`s, closes [#5100](https://github.com/tusen-ai/naive-ui/issues/5100).
- 修复 `n-spin` 动画异常问题,关闭 [#3556](https://github.com/tusen-ai/naive-ui/issues/3556)

### Features

Expand Down
129 changes: 51 additions & 78 deletions src/_internal/loading/src/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { ExtractPublicPropTypes } from '../../../_utils'
import NIconSwitchTransition from '../../icon-switch-transition'
import style from './styles/index.cssr'

const duration = '1.6s'

const exposedLoadingProps = {
strokeWidth: {
type: Number,
Expand Down Expand Up @@ -52,86 +54,57 @@ export default defineComponent({
{{
default: () =>
this.show ? (
<div
key="icon"
class={`${clsPrefix}-base-loading__transition-wrapper`}
>
<div class={`${clsPrefix}-base-loading__container`}>
<div class={`${clsPrefix}-base-loading__container-layer`}>
<div
class={`${clsPrefix}-base-loading__container-layer-left`}
>
<svg
class={`${clsPrefix}-base-loading__svg`}
viewBox={`0 0 ${2 * scaledRadius} ${
2 * scaledRadius
}`}
xmlns="http://www.w3.org/2000/svg"
style={{ color: stroke }}
>
<circle
fill="none"
stroke="currentColor"
stroke-width={strokeWidth}
stroke-linecap="round"
cx={scaledRadius}
cy={scaledRadius}
r={radius - strokeWidth / 2}
stroke-dasharray={4.91 * radius}
stroke-dashoffset={2.46 * radius}
/>
</svg>
</div>
<div
class={`${clsPrefix}-base-loading__container-layer-patch`}
>
<svg
class={`${clsPrefix}-base-loading__svg`}
viewBox={`0 0 ${2 * scaledRadius} ${
2 * scaledRadius
}`}
xmlns="http://www.w3.org/2000/svg"
style={{ color: stroke }}
>
<circle
fill="none"
stroke="currentColor"
stroke-width={strokeWidth}
stroke-linecap="round"
cx={scaledRadius}
cy={scaledRadius}
r={radius - strokeWidth / 2}
stroke-dasharray={4.91 * radius}
stroke-dashoffset={2.46 * radius}
/>
</svg>
</div>
<div
class={`${clsPrefix}-base-loading__container-layer-right`}
<div class={`${clsPrefix}-base-loading__container`}>
<svg
class={`${clsPrefix}-base-loading__icon`}
viewBox={`0 0 ${2 * scaledRadius} ${2 * scaledRadius}`}
xmlns="http://www.w3.org/2000/svg"
style={{ color: stroke }}
>
<g>
<animateTransform
attributeName="transform"
type="rotate"
values={`0 ${scaledRadius} ${scaledRadius};270 ${scaledRadius} ${scaledRadius}`}
begin="0s"
dur={duration}
fill="freeze"
repeatCount="indefinite"
/>
<circle
class={`${clsPrefix}-base-loading__icon`}
fill="none"
stroke="currentColor"
stroke-width={strokeWidth}
stroke-linecap="round"
cx={scaledRadius}
cy={scaledRadius}
r={radius - strokeWidth / 2}
stroke-dasharray={5.67 * radius}
stroke-dashoffset={18.48 * radius}
>
<svg
class={`${clsPrefix}-base-loading__svg`}
viewBox={`0 0 ${2 * scaledRadius} ${
2 * scaledRadius
<animateTransform
attributeName="transform"
type="rotate"
values={`0 ${scaledRadius} ${scaledRadius};135 ${scaledRadius} ${scaledRadius};450 ${scaledRadius} ${scaledRadius}`}
begin="0s"
dur={duration}
fill="freeze"
repeatCount="indefinite"
/>
<animate
attributeName="stroke-dashoffset"
values={`${5.67 * radius};${1.42 * radius};${
5.67 * radius
}`}
xmlns="http://www.w3.org/2000/svg"
style={{ color: stroke }}
>
<circle
fill="none"
stroke="currentColor"
stroke-width={strokeWidth}
stroke-linecap="round"
cx={scaledRadius}
cy={scaledRadius}
r={radius - strokeWidth / 2}
stroke-dasharray={4.91 * radius}
stroke-dashoffset={2.46 * radius}
/>
</svg>
</div>
</div>
</div>
begin="0s"
dur={duration}
fill="freeze"
repeatCount="indefinite"
/>
</circle>
</g>
</svg>
</div>
) : (
<div
Expand Down
170 changes: 23 additions & 147 deletions src/_internal/loading/src/styles/index.cssr.ts
Original file line number Diff line number Diff line change
@@ -1,167 +1,43 @@
import { c, cB, cE } from '../../../../_utils/cssr'
import { iconSwitchTransition } from '../../../../_styles/transitions/icon-switch.cssr'

export default c([
c('@keyframes loading-container-rotate', `
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
`),
c('@keyframes loading-layer-rotate', `
12.5% {
-webkit-transform: rotate(135deg);
transform: rotate(135deg);
}
25% {
-webkit-transform: rotate(270deg);
transform: rotate(270deg);
}
37.5% {
-webkit-transform: rotate(405deg);
transform: rotate(405deg);
}
50% {
-webkit-transform: rotate(540deg);
transform: rotate(540deg);
}
62.5% {
-webkit-transform: rotate(675deg);
transform: rotate(675deg);
}
75% {
-webkit-transform: rotate(810deg);
transform: rotate(810deg);
}
87.5% {
-webkit-transform: rotate(945deg);
transform: rotate(945deg);
c('@keyframes rotator', `
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(1080deg);
transform: rotate(1080deg);
}
`),
c('@keyframes loading-left-spin', `
from {
-webkit-transform: rotate(265deg);
transform: rotate(265deg);
}
50% {
-webkit-transform: rotate(130deg);
transform: rotate(130deg);
}
to {
-webkit-transform: rotate(265deg);
transform: rotate(265deg);
}
`),
c('@keyframes loading-right-spin', `
from {
-webkit-transform: rotate(-265deg);
transform: rotate(-265deg);
}
50% {
-webkit-transform: rotate(-130deg);
transform: rotate(-130deg);
}
to {
-webkit-transform: rotate(-265deg);
transform: rotate(-265deg);
}
`),
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}`
),
cB('base-loading', `
position: relative;
line-height: 0;
width: 1em;
height: 1em;
`, [
cE('transition-wrapper', `
position: absolute;
width: 100%;
height: 100%;
`, [
iconSwitchTransition()
]),
cE('container', `
display: inline-flex;
position: relative;
direction: ltr;
line-height: 0;
animation: loading-container-rotate 1568.2352941176ms linear infinite;
font-size: 0;
letter-spacing: 0;
white-space: nowrap;
opacity: 1;
width: 100%;
height: 100%;
`, [
cE('svg', `
stroke: var(--n-text-color);
fill: transparent;
position: absolute;
height: 100%;
overflow: hidden;
`),
cE('container-layer', `
position: absolute;
width: 100%;
height: 100%;
animation: loading-layer-rotate 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both;
`, [
cE('container-layer-left', `
display: inline-flex;
position: relative;
width: 50%;
height: 100%;
overflow: hidden;
`, [
cE('svg', `
animation: loading-left-spin 1333ms cubic-bezier(0.4, 0, 0.2, 1) infinite both;
width: 200%;
`)
]),
cE('container-layer-patch', `
position: absolute;
top: 0;
left: 47.5%;
box-sizing: border-box;
width: 5%;
height: 100%;
overflow: hidden;
`, [
cE('svg', `
left: -900%;
width: 2000%;
transform: rotate(180deg);
`)
]),
cE('container-layer-right', `
display: inline-flex;
position: relative;
width: 50%;
height: 100%;
overflow: hidden;
`, [
cE('svg', `
animation: loading-right-spin 1333ms cubic-bezier(0.4, 0, 0.2, 1) infinite both;
left: -100%;
width: 200%;
`)
])
])
]),
cE('placeholder', `
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
`, [
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
`, [
iconSwitchTransition({
left: '50%',
top: '50%',
originalTransform: 'translateX(-50%) translateY(-50%)'
})
]),
cE('container', `
animation: rotator 3s linear infinite both;
`, [
cE('icon', `
height: 1em;
width: 1em;
`, [
iconSwitchTransition()
])
])
])
])
22 changes: 22 additions & 0 deletions src/spin/demos/enUS/blocking-debug.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<markdown>
# Blocking method Debug

After invoked blocking method like `alert()`, you can still see the spin's rotating, but not the shrink and grow of the circle.
</markdown>

<template>
<n-space>
<n-button @click="handleClick">
Click to Report
</n-button>
<n-spin size="small" />
<n-spin size="medium" />
<n-spin size="large" />
</n-space>
</template>

<script lang="ts" setup>
const handleClick = () => {
window.alert('Reported!')
}
</script>
1 change: 1 addition & 0 deletions src/spin/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ wrap.vue
description.vue
customize-icon.vue
delay.vue
blocking-debug.vue
```

## API
Expand Down
Loading