Skip to content

Commit bcec7f3

Browse files
committed
use offsetWidth/Height in fix-auto
1 parent 5ad2948 commit bcec7f3

File tree

5 files changed

+89
-39
lines changed

5 files changed

+89
-39
lines changed

.size-snapshot.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"gzipped": 2150
66
},
77
"dist/web.umd.js": {
8-
"bundled": 87346,
9-
"minified": 36148,
10-
"gzipped": 12177
8+
"bundled": 89667,
9+
"minified": 36330,
10+
"gzipped": 12373
1111
}
1212
}

examples/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"react-router": "^4.3.1",
7171
"react-router-dom": "^4.2.2",
7272
"react-spring": "^4.0.1-beta.1",
73-
"react-with-gesture": "^1.0.9"
73+
"react-with-gesture": "^1.0.9",
74+
"styled-components": "^3.4.2"
7475
}
7576
}

examples/yarn.lock

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,13 @@ buffer@^4.3.0:
21452145
ieee754 "^1.1.4"
21462146
isarray "^1.0.0"
21472147

2148+
buffer@^5.0.3:
2149+
version "5.2.0"
2150+
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.2.0.tgz#53cf98241100099e9eeae20ee6d51d21b16e541e"
2151+
dependencies:
2152+
base64-js "^1.0.2"
2153+
ieee754 "^1.1.4"
2154+
21482155
builtin-modules@^1.0.0:
21492156
version "1.1.1"
21502157
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
@@ -2701,6 +2708,10 @@ [email protected], css-animation@^1.2.5, css-animation@^1.3.2:
27012708
babel-runtime "6.x"
27022709
component-classes "^1.2.5"
27032710

2711+
css-color-keywords@^1.0.0:
2712+
version "1.0.0"
2713+
resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
2714+
27042715
27052716
version "0.0.4"
27062717
resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"
@@ -2741,6 +2752,14 @@ css-selector-tokenizer@^0.7.0:
27412752
fastparse "^1.1.1"
27422753
regexpu-core "^1.0.0"
27432754

2755+
css-to-react-native@^2.0.3:
2756+
version "2.2.1"
2757+
resolved "https://registry.yarnpkg.com/css-to-react-native/-/css-to-react-native-2.2.1.tgz#7f3f4c95de65501b8720c87bf0caf1f39073b88e"
2758+
dependencies:
2759+
css-color-keywords "^1.0.0"
2760+
fbjs "^0.8.5"
2761+
postcss-value-parser "^3.3.0"
2762+
27442763
27452764
version "2.1.0"
27462765
resolved "https://registry.yarnpkg.com/css-what/-/css-what-2.1.0.tgz#9467d032c38cfaefb9f2d79501253062f87fa1bd"
@@ -3522,7 +3541,7 @@ fbjs@^0.8.0, fbjs@^0.8.16:
35223541
setimmediate "^1.0.5"
35233542
ua-parser-js "^0.7.9"
35243543

3525-
fbjs@^0.8.15, fbjs@^0.8.9:
3544+
fbjs@^0.8.15, fbjs@^0.8.5, fbjs@^0.8.9:
35263545
version "0.8.17"
35273546
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd"
35283547
dependencies:
@@ -6675,6 +6694,10 @@ react-dom@^16.3.2:
66756694
object-assign "^4.1.1"
66766695
prop-types "^15.6.0"
66776696

6697+
react-is@^16.3.1:
6698+
version "16.4.2"
6699+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.2.tgz#84891b56c2b6d9efdee577cc83501dfc5ecead88"
6700+
66786701
react-lazy-load@^3.0.12:
66796702
version "3.0.13"
66806703
resolved "https://registry.yarnpkg.com/react-lazy-load/-/react-lazy-load-3.0.13.tgz#3b0a92d336d43d3f0d73cbe6f35b17050b08b824"
@@ -7612,6 +7635,28 @@ style-loader@^0.20.3:
76127635
loader-utils "^1.1.0"
76137636
schema-utils "^0.4.5"
76147637

7638+
styled-components@^3.4.2:
7639+
version "3.4.2"
7640+
resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-3.4.2.tgz#8f518419932327e47fe9144824e3184b3e2da95d"
7641+
dependencies:
7642+
buffer "^5.0.3"
7643+
css-to-react-native "^2.0.3"
7644+
fbjs "^0.8.16"
7645+
hoist-non-react-statics "^2.5.0"
7646+
prop-types "^15.5.4"
7647+
react-is "^16.3.1"
7648+
stylis "^3.5.0"
7649+
stylis-rule-sheet "^0.0.10"
7650+
supports-color "^3.2.3"
7651+
7652+
stylis-rule-sheet@^0.0.10:
7653+
version "0.0.10"
7654+
resolved "https://registry.yarnpkg.com/stylis-rule-sheet/-/stylis-rule-sheet-0.0.10.tgz#44e64a2b076643f4b52e5ff71efc04d8c3c4a430"
7655+
7656+
stylis@^3.5.0:
7657+
version "3.5.3"
7658+
resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.5.3.tgz#99fdc46afba6af4deff570825994181a5e6ce546"
7659+
76157660
supports-color@^2.0.0:
76167661
version "2.0.0"
76177662
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
},
8989
"peerDependencies": {
9090
"prop-types": "15.x.x",
91-
"react": ">= 16.3.2",
92-
"react-dom": ">= 16.3.2"
91+
"react": ">= 16.4.0",
92+
"react-dom": ">= 16.4.0"
9393
},
9494
"dependencies": {
9595
"@babel/runtime": "7.0.0-beta.51"

src/targets/web/fix-auto.js

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,44 @@ export default function fixAuto(props, updateState) {
3232
style={{ ...elementStyles, position: 'absolute', visibility: 'hidden' }}
3333
ref={ref => {
3434
if (ref) {
35-
// Once it's rendered out, fetch bounds (minus padding/margin/borders)
36-
let node = ReactDOM.findDOMNode(ref)
37-
let width, height
38-
let cs = getComputedStyle(node)
39-
if (cs.boxSizing === 'border-box') {
40-
width = node.clientWidth
41-
height = node.clientHeight
42-
} else {
43-
const paddingX =
44-
parseFloat(cs.paddingLeft || 0) + parseFloat(cs.paddingRight || 0)
45-
const paddingY =
46-
parseFloat(cs.paddingTop || 0) + parseFloat(cs.paddingBottom || 0)
47-
const borderX =
48-
parseFloat(cs.borderLeftWidth || 0) +
49-
parseFloat(cs.borderRightWidth || 0)
50-
const borderY =
51-
parseFloat(cs.borderTopWidth || 0) +
52-
parseFloat(cs.borderBottomWidth || 0)
53-
width = node.offsetWidth - paddingX - borderX
54-
height = node.offsetHeight - paddingY - borderY
55-
}
35+
requestAnimationFrame(() => {
36+
// Once it's rendered out, fetch bounds (minus padding/margin/borders)
37+
let node = ReactDOM.findDOMNode(ref)
38+
let width, height
39+
let cs = getComputedStyle(node)
40+
if (cs.boxSizing === 'border-box') {
41+
width = node.offsetWidth
42+
height = node.offsetHeight
43+
} else {
44+
const paddingX =
45+
parseFloat(cs.paddingLeft || 0) +
46+
parseFloat(cs.paddingRight || 0)
47+
const paddingY =
48+
parseFloat(cs.paddingTop || 0) +
49+
parseFloat(cs.paddingBottom || 0)
50+
const borderX =
51+
parseFloat(cs.borderLeftWidth || 0) +
52+
parseFloat(cs.borderRightWidth || 0)
53+
const borderY =
54+
parseFloat(cs.borderTopWidth || 0) +
55+
parseFloat(cs.borderBottomWidth || 0)
56+
width = node.offsetWidth - paddingX - borderX
57+
height = node.offsetHeight - paddingY - borderY
58+
}
5659

57-
// Defer to next frame, or else the springs updateToken is canceled
58-
const convert = overwrite(width, height)
59-
updateState(
60-
{
61-
override: {
62-
...props,
63-
from: Object.entries(from).reduce(convert, from),
64-
to: Object.entries(to).reduce(convert, to),
60+
// Defer to next frame, or else the springs updateToken is canceled
61+
const convert = overwrite(width, height)
62+
updateState(
63+
{
64+
override: {
65+
...props,
66+
from: Object.entries(from).reduce(convert, from),
67+
to: Object.entries(to).reduce(convert, to),
68+
},
6569
},
66-
},
67-
false
68-
)
70+
false
71+
)
72+
})
6973
}
7074
}}
7175
/>

0 commit comments

Comments
 (0)