-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add percentage support to react native
Summary: Adds support for percentage value in react native. syntax: property: 100 | property | '100%' supported properties: padding margin width height minWidth minHeight maxWidth maxHeight flexBasis ``` class Playground extends React.Component { render() { return ( <View style={{backgroundColor: 'white', padding: 10, paddingTop: 30, height: '100%'}}> <Text> If you want to quickly test out something, open the Playground.js file and start coding. </Text> <View style={{backgroundColor: 'red', height: 50, width: 50}}/> <View style={{backgroundColor: 'blue', height: '50%', width: '50%'}}/> </View> ); } } ``` Reviewed By: astreet Differential Revision: D4376549 fbshipit-source-id: c41d68a7555396f95d063a7527ee081773ac56dc
- Loading branch information
1 parent
00d5674
commit 3f49e74
Showing
16 changed files
with
559 additions
and
208 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_YGValueTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* The examples provided by Facebook are for non-commercial testing and | ||
* evaluation purposes only. | ||
* | ||
* Facebook reserves all rights not expressly granted. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL | ||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import <React/RCTConvert.h> | ||
#import <React/RCTUtils.h> | ||
|
||
@interface RCTConvert_YGValueTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation RCTConvert_YGValueTests | ||
|
||
- (void)testUndefined | ||
{ | ||
YGValue value = [RCTConvert YGValue:nil]; | ||
XCTAssertEqual(value.unit, YGUnitUndefined); | ||
} | ||
|
||
- (void)testNumberPoints | ||
{ | ||
YGValue value = [RCTConvert YGValue:@100]; | ||
XCTAssertEqual(value.unit, YGUnitPixel); | ||
XCTAssertEqual(value.value, 100); | ||
} | ||
|
||
- (void)testStringPercent | ||
{ | ||
YGValue value = [RCTConvert YGValue:@"100%"]; | ||
XCTAssertEqual(value.unit, YGUnitPercent); | ||
XCTAssertEqual(value.value, 100); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilsjolander Can these values be animated with Animated? :O
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amazing work
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henrikra i dont see why not. May need some changes in RN though
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilsjolander Maybe you should try and add example to the docs? Since this changes so many things
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@henrikra i know this is on the todo list for RN. Feel free to help us out with doc PRs :)
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilsjolander I tried this today and it worked nicely with width and height. When I tried like
left: 50%
it did not work like expected. I am sure you know this already though :D3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not. Please file an issue over at facebook/yoga
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilsjolander Look like it has to do something with
flexDirection: 'row'
. Here is the issue I did: #12660 :) Tell me if you need more info.3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't believe it's happening 😱 Great job @emilsjolander !!!
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emilsjolander I am trying to use this on Android, with react-native v0.51.0 and got this error:
Error while updating property 'width' in shadow node of type: RCTViewnullInvalid float: "90%"
On iOS its working normally. I will open an issue ticket.
Thanks for this feature
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! One question, any reason this is not documented yet? is it ready to use in production?
3f49e74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature is really nice but the fact it remains undocumented for so long prevents me from using it on production