Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
300c4d01
提交
300c4d01
authored
4月 28, 2018
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve size hoc
上级
de701f2f
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
20 行删除
+32
-20
CheckSize.js
src/components/hoc/CheckSize.js
+22
-0
size.js
src/components/hoc/size.js
+10
-20
没有找到文件。
src/components/hoc/CheckSize.js
0 → 100644
浏览文件 @
300c4d01
import
React
from
'react'
;
import
PropTypes
from
'prop-types'
;
import
{
shallowEqual
}
from
'../../utils/helper'
;
class
CheckSize
extends
React
.
Component
{
shouldComponentUpdate
(
nextProps
,
nextState
,
nextContext
)
{
return
!
shallowEqual
(
this
.
props
.
size
,
nextProps
.
size
)
||
!
shallowEqual
(
this
.
props
,
nextProps
,
[
'size'
,
'children'
])
||
!
shallowEqual
(
this
.
state
,
nextState
)
||
!
shallowEqual
(
this
.
context
,
nextContext
);
}
render
()
{
return
this
.
props
.
children
||
null
;
}
}
CheckSize
.
propTypes
=
{
size
:
PropTypes
.
object
,
};
export
default
CheckSize
;
src/components/hoc/size.js
浏览文件 @
300c4d01
import
React
from
'react'
;
import
React
from
'react'
;
import
PropTypes
from
'prop-types'
;
import
sm
from
'react-sizeme'
;
import
sm
from
'react-sizeme'
;
import
hoistStatics
from
'hoist-non-react-statics'
;
import
hoistStatics
from
'hoist-non-react-statics'
;
import
{
shallowEqual
}
from
'../../utils/helper'
;
import
{
shallowEqual
}
from
'../../utils/helper'
;
import
CheckSize
from
'./CheckSize'
;
const
SizeMeContext
=
React
.
createContext
(
'sizeMe'
);
const
SizeMeContext
=
React
.
createContext
(
'sizeMe'
);
export
const
{
Provider
,
Consumer
}
=
SizeMeContext
;
export
const
{
Provider
,
Consumer
}
=
SizeMeContext
;
export
const
provideSize
=
options
=>
(
Component
)
=>
{
export
const
provideSize
=
options
=>
(
Component
)
=>
{
const
WrappedComponent
=
({
size
,
forwardedRef
,
children
,
...
rest
})
=>
{
const
WC
=
class
WrappedComponent
extends
React
.
Component
{
render
()
{
const
{
size
,
forwardedRef
,
children
,
...
rest
}
=
this
.
props
;
if
(
!
shallowEqual
(
this
.
size
,
size
))
{
this
.
size
=
size
;
}
return
(
return
(
<
Provider
value
=
{
size
}
>
<
Provider
value
=
{
this
.
size
}
>
<
Component
ref
=
{
forwardedRef
}
{...
rest
}
>
<
Component
ref
=
{
forwardedRef
}
{...
rest
}
>
{
children
||
null
}
{
children
||
null
}
<
/Component
>
<
/Component
>
<
/Provider
>
<
/Provider
>
);
);
}
};
};
const
SizeMeComponent
=
sm
(
options
)(
W
rappedComponent
);
const
SizeMeComponent
=
sm
(
options
)(
W
C
);
const
C
=
React
.
forwardRef
((
props
,
ref
)
=>
(
const
C
=
React
.
forwardRef
((
props
,
ref
)
=>
(
<
SizeMeComponent
forwardedRef
=
{
ref
}
{...
props
}
/
>
<
SizeMeComponent
forwardedRef
=
{
ref
}
{...
props
}
/
>
));
));
...
@@ -28,22 +34,6 @@ export const provideSize = options => (Component) => {
...
@@ -28,22 +34,6 @@ export const provideSize = options => (Component) => {
export
const
provideWidth
=
provideSize
({});
export
const
provideWidth
=
provideSize
({});
export
const
provideHeight
=
provideSize
({
monitorHeight
:
true
});
export
const
provideHeight
=
provideSize
({
monitorHeight
:
true
});
class
CheckSize
extends
React
.
Component
{
shouldComponentUpdate
(
nextProps
,
nextState
,
nextContext
)
{
return
!
shallowEqual
(
this
.
props
.
size
,
nextProps
.
size
)
||
!
shallowEqual
(
this
.
props
,
nextProps
,
[
'size'
,
'children'
])
||
!
shallowEqual
(
this
.
state
,
nextState
)
||
!
shallowEqual
(
this
.
context
,
nextContext
);
}
render
()
{
return
this
.
props
.
children
||
null
;
}
}
CheckSize
.
propTypes
=
{
size
:
PropTypes
.
object
,
};
export
const
withSize
=
(
Component
)
=>
{
export
const
withSize
=
(
Component
)
=>
{
const
C
=
React
.
forwardRef
((
props
,
ref
)
=>
(
const
C
=
React
.
forwardRef
((
props
,
ref
)
=>
(
<
Consumer
>
<
Consumer
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论