Skip to content

Commit

Permalink
feat(stylesheet): add support to turn on/off the responsive size func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
feyy committed May 2, 2016
1 parent 683b4e2 commit 8f97a8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ StyleSheet.r(100); // 113 (width: 360, base: 320)
| setBase | width:number | set the target width according to the UI |
| create | style:object | replace native StyleSheet creating stylesheet |
| r | num:number | the inner function to get the responsive size according to the device with and base |
| switchR | isRon:boolean | set the flag to switch the responsive size function, which return the prev value |
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const DEFAULT_WIDTH = 320;
const CStyleSheet = {
baseWidth: DEFAULT_WIDTH,
ratio: width / DEFAULT_WIDTH,
isROn: true,
setBase: function (baseWidth = DEFAULT_WIDTH) {
this.baseWidth = baseWidth;
this.ratio = width / baseWidth;
Expand Down Expand Up @@ -67,12 +68,20 @@ const CStyleSheet = {
return styleObj;
},

switchR: function(isROn) {
var prevStatus = this.isROn;

this.isROn = !!isROn;

return prevStatus;
},

r: function(num) {
if (Math.abs(num) <= 1) {
return num;
if (this.isROn && Math.abs(num) > 1) {
return Math.round(num * this.ratio);
}

return Math.round(num * this.ratio);
return num;
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-stylesheet-xg",
"version": "1.0.2",
"version": "1.0.3",
"description": "extension stylesheet for cross platforms and responsive",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 8f97a8e

Please sign in to comment.