Commit 7c637408 by fukai

支持新钩子

parent f75165df
...@@ -83,6 +83,7 @@ class LiveRoute extends React.Component<PropsType, any> { ...@@ -83,6 +83,7 @@ class LiveRoute extends React.Component<PropsType, any> {
public previousDisplayStyle: string | null = null public previousDisplayStyle: string | null = null
public liveState: LiveState = LiveState.NORMAL_RENDER_ON_INIT public liveState: LiveState = LiveState.NORMAL_RENDER_ON_INIT
public currentSideEffect: SideEffect[] = [SideEffect.NO_SIDE_EFFECT] public currentSideEffect: SideEffect[] = [SideEffect.NO_SIDE_EFFECT]
public wrapperedRef:any = null
public componentDidMount() { public componentDidMount() {
this.getRouteDom() this.getRouteDom()
...@@ -105,10 +106,16 @@ class LiveRoute extends React.Component<PropsType, any> { ...@@ -105,10 +106,16 @@ class LiveRoute extends React.Component<PropsType, any> {
this.clearScroll() this.clearScroll()
} }
public passRef = (ref) =>
{
this.wrapperedRef = ref
}
// get DOM of Route // get DOM of Route
public getRouteDom = () => { public getRouteDom = (ref?:any) => {
let routeDom = ReactDOM.findDOMNode(this) let routeDom = ReactDOM.findDOMNode(this)
this.routeDom = (routeDom as CacheDom) || this.routeDom this.routeDom = (routeDom as CacheDom) || this.routeDom
ref && this.passRef(ref)
} }
public hideRoute() { public hideRoute() {
...@@ -256,7 +263,7 @@ class LiveRoute extends React.Component<PropsType, any> { ...@@ -256,7 +263,7 @@ class LiveRoute extends React.Component<PropsType, any> {
staticContext staticContext
// from withRouter, same as RouterContext.Consumer ⬆️ // from withRouter, same as RouterContext.Consumer ⬆️
} = this.props } = this.props
const hook = this[hookName] const hook = this.props[hookName]
const context = { history, location, match, staticContext } const context = { history, location, match, staticContext }
const matchOfPath = this.props.path ? matchPath(location.pathname, this.props) : context.match const matchOfPath = this.props.path ? matchPath(location.pathname, this.props) : context.match
const matchOfLivePath = this.isLivePathMatch(livePath, alwaysLive, location!.pathname, { const matchOfLivePath = this.isLivePathMatch(livePath, alwaysLive, location!.pathname, {
...@@ -266,6 +273,15 @@ class LiveRoute extends React.Component<PropsType, any> { ...@@ -266,6 +273,15 @@ class LiveRoute extends React.Component<PropsType, any> {
sensitive sensitive
}) })
const matchAnyway = matchOfPath || matchOfLivePath const matchAnyway = matchOfPath || matchOfLivePath
if(hookName == 'onHide')
{
this.wrapperedRef && this.wrapperedRef.componentOnHide && this.wrapperedRef.componentOnHide(location!, matchAnyway, history, livePath, alwaysLive)
}else if(hookName == 'onReappear')
{
this.wrapperedRef && this.wrapperedRef.componentOnReappear && this.wrapperedRef.componentOnReappear(location!, matchAnyway, history, livePath, alwaysLive)
}
if (typeof hook === 'function') { if (typeof hook === 'function') {
hook(location!, matchAnyway, history, livePath, alwaysLive) hook(location!, matchAnyway, history, livePath, alwaysLive)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment