nuke-helper
Advanced tools
Comparing version 0.0.6 to 0.0.7
# demo | ||
- order: 0 | ||
* order: 0 | ||
@@ -9,4 +9,3 @@ Helper demo | ||
````js | ||
```js | ||
/** @jsx createElement */ | ||
@@ -18,3 +17,3 @@ import { createElement, Component, render } from 'rax'; | ||
const { hairLine, borderSeperate,calcTextSize } = Helper; | ||
const { hairLine, borderSeperate, calcTextSize } = Helper; | ||
@@ -30,15 +29,21 @@ let App = class NukeDemoIndex extends Component { | ||
<Text>support hairline:{hairLine.detect()}</Text> | ||
<Text>hairline border:{JSON.stringify(hairLine.fixBorder({ borderWidth: 1 }))}</Text> | ||
<Text>border:{JSON.stringify(borderSeperate({ borderWidth: 1, borderTopWidth: 3 }))}</Text> | ||
<Text>font:{JSON.stringify(calcTextSize( {fontSize: '28rem'}))}</Text> | ||
<Text>font:{JSON.stringify(calcTextSize( {fontSize: '14px'}))}</Text> | ||
<Text> | ||
hairline border:{JSON.stringify( | ||
hairLine.fixBorder({ borderWidth: 1 }) | ||
)} | ||
</Text> | ||
<Text> | ||
border:{JSON.stringify( | ||
borderSeperate({ borderWidth: 1, borderTopWidth: 3 }) | ||
)} | ||
</Text> | ||
<Text>font:{JSON.stringify(calcTextSize({ fontSize: '28rem' }))}</Text> | ||
<Text>font:{JSON.stringify(calcTextSize({ fontSize: 28 }))}</Text> | ||
<Text>font:{JSON.stringify(calcTextSize({ fontSize: '14px' }))}</Text> | ||
</View> | ||
); | ||
} | ||
} | ||
}; | ||
render(<App />); | ||
```` | ||
``` |
# Changelog | ||
## 0.0.7 / 2018-01-15 | ||
* [[a66c53d](http://gitlab.alibaba-inc.com/nuke/helper/commit/a66c53d317f0621ebf01805baf4a8be7363ba3e7)] - `feat` fit size for ipad | ||
## 0.0.6 / 2018-01-05 | ||
@@ -5,0 +9,0 @@ |
@@ -11,6 +11,44 @@ 'use strict'; | ||
var isIpad = void 0; | ||
if (_universalEnv.isWeb) { | ||
isIpad = navigator.userAgent.indexOf('iPad') > -1; | ||
} else { | ||
isIpad = __weex_env__.platform.toLowerCase() === 'ios' && __weex_env__.deviceModel.toLowerCase().indexOf('ipad') > -1; | ||
} | ||
function fitPad(style) { | ||
var result = _extends({}, style); | ||
var fontSize = style.fontSize; | ||
if (typeof fontSize === 'string' && fontSize.indexOf('rem') > 0 || typeof fontSize === 'number') { | ||
fontSize = parseInt(fontSize, 10); | ||
} | ||
if (typeof fontSize === 'string' && fontSize.indexOf('px') > 0) { | ||
fontSize = parseInt(fontSize, 10) * 2; | ||
} | ||
result.fontSize = fontSize; | ||
return result; | ||
} | ||
// appInfo.platform.toLowerCase() === 'ios' && | ||
// appInfo.deviceModel.toLowerCase() === 'ipad'; | ||
/** | ||
* parse fontSize to a fixed font. | ||
* if style: | ||
* fontSize:'28rem' or | ||
* fontSize:28, or | ||
* fontSize:'14px' | ||
* and fixedFont=true | ||
* will turns to: | ||
* font-size 14px (in web) / 14wx (in ios and android weex ). | ||
* But if in ipad, things go other way, if you choose fitPad, font-size will roll back to rem to fit screen. | ||
*/ | ||
exports.default = function (style) { | ||
var fixedFont = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var shouldFitPad = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
if (!style || !style.fontSize || !fixedFont) return style; | ||
if (isIpad && shouldFitPad) return fitPad(style); | ||
var result = _extends({}, style); | ||
@@ -25,2 +63,3 @@ var fontSize = style.fontSize; | ||
result.fontSize = fontSize + (_universalEnv.isWeb ? 'px' : 'wx'); | ||
if (isIpad && fitPad) {} | ||
return result; | ||
@@ -27,0 +66,0 @@ }; |
{ | ||
"name": "nuke-helper", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "辅助函数", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
12513
216