-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
DiamondYuan
committed
Nov 17, 2023
1 parent
a21fac5
commit 31892da
Showing
10 changed files
with
167 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,66 @@ | ||
import { PopupDefaultProps } from './props'; | ||
import { compareVersion } from '../_util/compareVersion'; | ||
import { useState, useEvent } from 'functional-mini/component'; | ||
import '../_util/assert-component2'; | ||
import { mountComponent } from '../_util/component'; | ||
import { useComponentEvent } from '../_util/hooks/useComponentEvent'; | ||
import { useLayoutUpdateEffect } from '../_util/hooks/useLayoutEffect'; | ||
import { isOldSDKVersion } from '../_util/platform'; | ||
import { IPopupProps } from './props'; | ||
|
||
const SDKVersion = my.SDKVersion; | ||
const isOldVersion = compareVersion(SDKVersion, '2.0.0') < 0; | ||
const component2 = my.canIUse('component2'); | ||
const isOldVersion = isOldSDKVersion(); | ||
|
||
Component({ | ||
props: PopupDefaultProps, | ||
data: { | ||
closing: false, | ||
isOldVersion, | ||
}, | ||
didUpdate(prevProps) { | ||
if (component2) { | ||
return; | ||
} | ||
const { visible, duration, animation } = this.props; | ||
if (prevProps.visible && !visible) { | ||
if (animation && duration > 0) { | ||
this.setData({ closing: true }); | ||
} | ||
} | ||
}, | ||
deriveDataFromProps(nextProps) { | ||
const { visible, duration, animation } = nextProps; | ||
if (this.props.visible && !visible) { | ||
if (animation && duration > 0) { | ||
this.setData({ closing: true }); | ||
} | ||
const Popup = (props: IPopupProps) => { | ||
const enableAnimation = props.animation && props.duration > 0; | ||
const [closing, setClosing] = useState(false); | ||
|
||
const { triggerEventOnly } = useComponentEvent(props); | ||
|
||
useLayoutUpdateEffect(() => { | ||
if (!props.visible && enableAnimation) { | ||
setClosing(true); | ||
} | ||
}, | ||
methods: { | ||
onTapMask() { | ||
const { closing } = this.data; | ||
}, [props.visible]); | ||
|
||
useEvent( | ||
'onAnimationEnd', | ||
() => { | ||
if (closing) { | ||
return; | ||
} | ||
const { onClose } = this.props; | ||
if (onClose) { | ||
onClose(); | ||
setClosing(false); | ||
} | ||
}, | ||
onAnimationEnd() { | ||
const { closing } = this.data; | ||
[closing] | ||
); | ||
|
||
useEvent( | ||
'onTapMask', | ||
() => { | ||
if (closing) { | ||
this.setData({ closing: false }); | ||
return; | ||
} | ||
triggerEventOnly('close'); | ||
}, | ||
}, | ||
[closing] | ||
); | ||
|
||
return { | ||
closing, | ||
isOldVersion, | ||
}; | ||
}; | ||
|
||
mountComponent(Popup, { | ||
visible: false, | ||
destroyOnClose: false, | ||
showMask: true, | ||
position: 'bottom', | ||
// 是否开启动画 | ||
animation: true, | ||
animationType: 'transform', | ||
// 动画持续时间 | ||
duration: 300, | ||
height: null, | ||
width: null, | ||
maskClassName: '', | ||
maskStyle: '', | ||
// 弹窗层级 | ||
zIndex: 998, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,66 @@ | ||
import { PopupDefaultProps } from './props'; | ||
import { compareVersion } from '../_util/compareVersion'; | ||
import { useState, useEvent } from 'functional-mini/component'; | ||
import '../_util/assert-component2'; | ||
import { mountComponent } from '../_util/component'; | ||
import { useComponentEvent } from '../_util/hooks/useComponentEvent'; | ||
import { useLayoutUpdateEffect } from '../_util/hooks/useLayoutEffect'; | ||
import { isOldSDKVersion } from '../_util/platform'; | ||
import { IPopupProps } from './props'; | ||
|
||
const SDKVersion = my.SDKVersion; | ||
const isOldVersion = compareVersion(SDKVersion, '2.0.0') < 0; | ||
const component2 = my.canIUse('component2'); | ||
const isOldVersion = isOldSDKVersion(); | ||
|
||
Component({ | ||
props: PopupDefaultProps, | ||
data: { | ||
closing: false, | ||
isOldVersion, | ||
}, | ||
didUpdate(prevProps) { | ||
if (component2) { | ||
return; | ||
} | ||
const { visible, duration, animation } = this.props; | ||
if (prevProps.visible && !visible) { | ||
if (animation && duration > 0) { | ||
this.setData({ closing: true }); | ||
} | ||
} | ||
}, | ||
deriveDataFromProps(nextProps) { | ||
const { visible, duration, animation } = nextProps; | ||
if (this.props.visible && !visible) { | ||
if (animation && duration > 0) { | ||
this.setData({ closing: true }); | ||
} | ||
const Popup = (props: IPopupProps) => { | ||
const enableAnimation = props.animation && props.duration > 0; | ||
const [closing, setClosing] = useState(false); | ||
|
||
const { triggerEventOnly } = useComponentEvent(props); | ||
|
||
useLayoutUpdateEffect(() => { | ||
if (!props.visible && enableAnimation) { | ||
setClosing(true); | ||
} | ||
}, | ||
methods: { | ||
onTapMask() { | ||
const { closing } = this.data; | ||
}, [props.visible]); | ||
|
||
useEvent( | ||
'onAnimationEnd', | ||
() => { | ||
if (closing) { | ||
return; | ||
} | ||
const { onClose } = this.props; | ||
if (onClose) { | ||
onClose(); | ||
setClosing(false); | ||
} | ||
}, | ||
onAnimationEnd() { | ||
const { closing } = this.data; | ||
[closing] | ||
); | ||
|
||
useEvent( | ||
'onTapMask', | ||
() => { | ||
if (closing) { | ||
this.setData({ closing: false }); | ||
return; | ||
} | ||
triggerEventOnly('close'); | ||
}, | ||
}, | ||
[closing] | ||
); | ||
|
||
return { | ||
closing, | ||
isOldVersion, | ||
}; | ||
}; | ||
|
||
mountComponent(Popup, { | ||
visible: false, | ||
destroyOnClose: false, | ||
showMask: true, | ||
position: 'bottom', | ||
// 是否开启动画 | ||
animation: true, | ||
animationType: 'transform', | ||
// 动画持续时间 | ||
duration: 300, | ||
height: null, | ||
width: null, | ||
maskClassName: '', | ||
maskStyle: '', | ||
// 弹窗层级 | ||
zIndex: 998, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.