Commit Graph

834 Commits

Author SHA1 Message Date
Dustin Shahidehpour
129437f49e Change CLK prefix on static functions to CSS.
Summary: Talked with emilsjolander offline, and we want to keep the prefixes standardized in this lib. Changing CLK prefixes to CSS.

Reviewed By: emilsjolander

Differential Revision: D4175634

fbshipit-source-id: 7152268b9312df3fdb8eaee7ce3f6baabc5de937
2016-11-14 13:22:52 -08:00
Fred Liu
204aba80b9 Revert D4157971: [csslayout] BREAKING - Fix sizing of container with child overflowing parent
Summary: This reverts commit 3cfae15ac8b65b70f01789444099ee684e1b099a

Differential Revision: D4157971

fbshipit-source-id: be055cf018fd39b3cee9af0bc777831fcf757190
2016-11-14 12:22:58 -08:00
Emil Sjolander
e6702e1168 Implement standard interface for toggling experimental features
Summary: We want to start experimenting with changes to the library in a more controlled and easier to measure manner. This diff adds the basics of an experiment layer to csslayout.

Reviewed By: gkassabli

Differential Revision: D4174260

fbshipit-source-id: ad3667183810c02833fba9a1276f89286e848fcd
2016-11-14 03:37:45 -08:00
Emil Sjolander
b99172d28b rename CSSWrapType to shorter CSSWrap matching java and csharp
Summary: Java and csharp already use CSSWrap and not CSSWrapType. Let's consolidate and stick with the shorter of the two.

Reviewed By: gkassabli

Differential Revision: D4174257

fbshipit-source-id: ba0bfab996ba158b07863d8c72cf2a41262c9592
2016-11-14 03:37:45 -08:00
Emil Sjolander
7a3df9999b BREAKING - Fix sizing of container with child overflowing parent
Summary:
Fixes issue brought up in https://github.com/facebook/react-native/issues/10603

The gist of the problem is that in css it is fine for a child to overflow a parent if it feels the need to, we were not respecting this.

Reviewed By: gkassabli

Differential Revision: D4157971

fbshipit-source-id: 3cfae15ac8b65b70f01789444099ee684e1b099a
2016-11-14 02:22:44 -08:00
Dustin Shahidehpour
e0e88f97b6 Cleanup documentation, add pragma marks, and rename static functions in UIView+CSSLayout
Summary: There is a little bit of tidying that was needed for this class. The documentation was inconsistent in the header, the static functions were prefixed with underscores (discouraged by apple). Cleaned it all up.

Reviewed By: rnystrom

Differential Revision: D4167936

fbshipit-source-id: 6e9a6e7fb78e3cff290b867a1ac0d5dd5cc9de5b
v2016.11.14.00
2016-11-11 16:52:47 -08:00
Dustin Shahidehpour
b4d0e1a17c Add some more compiler flags to CSSLayoutKit.
Summary: Just firming up some stuff with more compiler flags.

Reviewed By: rnystrom

Differential Revision: D4168081

fbshipit-source-id: fced407f03944081bdd70cc28c57e3dc842ff7f0
2016-11-11 15:07:35 -08:00
Kazuki Sakamoto
e40af30fa5 Update .travis.yml for C# test
Summary: Closes https://github.com/facebook/css-layout/pull/246

Reviewed By: emilsjolander

Differential Revision: D4167133

Pulled By: splhack

fbshipit-source-id: d55c0ff5155311f4da859b12b6485b120dac480b
2016-11-11 09:07:44 -08:00
Emil Sjolander
cd054ecf26 Expose CSSLayoutSetLogger to java
Summary: Expose CSSLayoutSetLogger to java

Reviewed By: astreet

Differential Revision: D4153502

fbshipit-source-id: 630909d9d0d36d94d7cd3027476ddb52668b8cc0
2016-11-11 08:23:14 -08:00
Emil Sjolander
aaa977f645 Fix flex within max size if max size is not constraint to
Summary: Previous fix for flex in max size constraint was not entirely correct and was missing a test case for the time when the max constraint is not applied. This diff addresses that.

Reviewed By: gkassabli

Differential Revision: D4162104

fbshipit-source-id: 08feba6cb4e789c9aa12179e2cdeadc66b011841
2016-11-11 08:07:42 -08:00
Dustin Shahidehpour
70e01a4476 Rename uikit/CSSLayout to CSSLayoutKit.
Summary:
When trying to integrate this into an Xcode project that already included CSSLayout.[c|h], we were getting a linker error.

Upon digging in, I found out that Xcode was becoming confused because the imports of the uikit library and the c library are both `#import <CSSLayout/CSSLayout.h>`. So, it needed a new name.

Reviewed By: emilsjolander

Differential Revision: D4162621

fbshipit-source-id: b5f7624eb29f1b9eaebbed5104ec9ea8a12ad2e5
2016-11-11 07:38:15 -08:00
Emil Sjolander
3e2c13f418 Fix running ios tests in travis
Summary: Currently travis logs indicate it is building with the wrong cxx platform. Explicitly set this to and ios simulator for ios tests

Reviewed By: dshahidehpour

Differential Revision: D4162159

fbshipit-source-id: 50f563132456ee4ba4e5b3b4b1f50b636cb94306
2016-11-10 19:52:56 -08:00
Kazuki Sakamoto
0dbbfc5910 Add convenient cast method for MeasureOutput.Make
Summary: Same as Java, it allows to use float and double values in Make arguments.

Reviewed By: emilsjolander

Differential Revision: D4163347

fbshipit-source-id: f373247b3f37e7940a66044000cca2935068decf
2016-11-10 19:22:36 -08:00
Pieter De Baets
f222d22ba8 Remove useless store in CSSLayout.c
Summary: Pointed out by the Xcode analyzer

Reviewed By: emilsjolander

Differential Revision: D4159938

fbshipit-source-id: 8b9ff3896c0e222e8e89546881129214bc6ba566
2016-11-10 08:53:05 -08:00
Emil Sjolander
087d1f3a82 Fix benchmark
Summary: It was always a mistake to have a measure function here but the recent addition of an assertion made us notice it.

Reviewed By: splhack

Differential Revision: D4156754

fbshipit-source-id: 98fcea6e233cb4f5706ebca37028c8d67edb4c09
2016-11-09 20:22:41 -08:00
Kazuki Sakamoto
c382d513fb Remove CSSAssertSetFailFunc
Summary: Remove CSSAssertSetFailFunc and use CSSLogLevelError for throwing managed exception.

Reviewed By: emilsjolander

Differential Revision: D4155452

fbshipit-source-id: 5a19c79a212f204d13064527fd6e5843bab76e6b
2016-11-09 17:38:10 -08:00
Kazuki Sakamoto
8a7183f465 Add tests for SetMeasureFunction
Summary: Add tests for checking C side asserts in managed

Reviewed By: emilsjolander

Differential Revision: D4154869

fbshipit-source-id: 5203db27eff963d46f188de448f607a24ed63fab
2016-11-09 13:23:00 -08:00
Emil Sjolander
ff602d4606 Absolute positioned items should apear inside padding but outside border
Summary:
Absolute positioned elements were not correctly respecting border / padding.

https://github.com/facebook/css-layout/issues/245
fixes #245

Reviewed By: gkassabli

Differential Revision: D4153332

fbshipit-source-id: 251e29e02018a433f60349b78c03feb121512797
2016-11-09 11:52:54 -08:00
Emil Sjolander
f5912a97e4 Fix issues with running test in open source
Summary: Travis builds have been broken for a while. This diff fixes some of the issues surrounding bad buck file configuration as well as missing jni.h file.

Reviewed By: astreet

Differential Revision: D4148724

fbshipit-source-id: 1e284db61280326a4bcbb9337e804a4804348aa6
2016-11-09 11:37:48 -08:00
Emil Sjolander
a253c6fbb7 Dont measure single flex grow+shrink child
Summary:
If there is a single child which is flex grow and flex shrink then instead of measuring and then shrinking we can just set the flex basis to zero as we know the final result will be that the child take up all remaining space.

This is a re-land of D4147298. I have updated the diff to check explicitly for exact measure mode to also handle at_most case correctly.

Reviewed By: gkassabli

Differential Revision: D4153133

fbshipit-source-id: 2333150a83857cc30078cc8d52761cbd00652830
2016-11-09 11:37:48 -08:00
Kazuki Sakamoto
863378d74e Sync Logger API
Summary: - Sync Logger API with C implementation

Reviewed By: emilsjolander

Differential Revision: D4143019

fbshipit-source-id: f20203320bad5b8f4b9cce01a5b2e7c615a4d923
2016-11-09 10:22:42 -08:00
Andy Street
f1fcd5e382 Update logging to support levels, print messages in Android logcat on assertion failures
Summary:
@public

The goal of this diff is to have assertion failures show up as error logs on Android. To do this, I updated the logging API to take calls with log levels. We now have to pass around va_list unfortunately since you can't re-expand or pass along var-args to a subcall.

Reviewed By: emilsjolander

Differential Revision: D4140898

fbshipit-source-id: e0eb9a1f0b08a7d90a8233f66bb857d5b871b6ad
2016-11-09 09:52:43 -08:00
Emil Sjolander
6a6efe0764 change default value of position styles
Summary: Default value for positions should be undefined not 0px. Fixing this leads to more correct tests.

Reviewed By: gkassabli

Differential Revision: D4153329

fbshipit-source-id: d0f194f9c47eac93d3815ec7e55568a1016bc7fe
2016-11-09 09:22:40 -08:00
Dustin Shahidehpour
e54af5e854 Allow MeasureFunc to be set to NULL no matter how many children a node has.
Summary: Within `UIView+CSSLayout`, we often nil out the measure function of a node because view hierarchy can often change. Unfortunately, this causes us to hit an assert which crashes the app. Instead, lets the measure func to be set to NULL, regardless of how many children a node might have.

Reviewed By: emilsjolander

Differential Revision: D4148727

fbshipit-source-id: 79a0f3ef1bf7b1dce9a14de96f870e35c042b78b
2016-11-09 08:52:45 -08:00
Jing Chen
502f3c7010 Reverted commit D4147298
Summary: If there is a single child which is flex grow and flex shrink then instead of measuring and then shrinking we can just set the flex basis to zero as we know the final result will be that the child take up all remaining space.

Reviewed By: gkassabli

Differential Revision: D4147298

fbshipit-source-id: 8416508a31e8d317bf59d956abdbe5760b55bb6d
2016-11-09 00:07:45 -08:00
Emil Sjolander
12ebaa56b6 Dont measure single flex grow+shrink child
Summary: If there is a single child which is flex grow and flex shrink then instead of measuring and then shrinking we can just set the flex basis to zero as we know the final result will be that the child take up all remaining space.

Reviewed By: gkassabli

Differential Revision: D4147298

fbshipit-source-id: 51152e57eff8e322a833a6d698c30f8c5e2dcc35
2016-11-08 15:37:48 -08:00
Emil Sjolander
3e567fdcae Fix flex within max width constraint
Summary:
Max dimension constraints were not correctly passed down to children.

see https://github.com/facebook/css-layout/issues/230 for more info
fixes #230

Reviewed By: gkassabli

Differential Revision: D4147199

fbshipit-source-id: feb335eb8687a1b7939ee8cd8649e455e0c069a9
2016-11-08 09:53:00 -08:00
Emil Sjolander
1baa239389 Remove isTextNode optimization
Summary: Scrolling through feed and logging when this optimization is hit leads to... 0 logs. If anything this just adds to confusion. It was initially added due to instinct and not data, which was a mistake. I am happy to add some similar optimization in the future if we have data that it is useful in real world situations, currently it just leads to bugs and confusion though.

Reviewed By: astreet

Differential Revision: D4146785

fbshipit-source-id: e20d780fbd5759b8f38b809e8cadf29cedee82a8
2016-11-08 09:22:38 -08:00
Dustin Shahidehpour
b50090a04e NSAssert -> NSCAssert.
Summary: Not sure why this didn't catch during my testing, but, this causes a build error. #accept2ship

Reviewed By: emilsjolander

Differential Revision: D4143108

fbshipit-source-id: 01c35c5b91767c95485d615eb06e836b023e125a
2016-11-08 07:22:48 -08:00
Kazuki Sakamoto
ba2905dd1d Add C# test script for macOS
Summary: - Updated README and added bash script for testing C# on macOS

Reviewed By: emilsjolander

Differential Revision: D4142507

fbshipit-source-id: c682778e42d10242e02f3fdafe8a23f906bfabc5
2016-11-07 19:37:57 -08:00
Dustin Shahidehpour
997088ffbb Fix broken unit tests.
Summary: For some reason I didn't get a signal of this breakage. Fixing unit tests.

Reviewed By: emilsjolander

Differential Revision: D4140327

fbshipit-source-id: 95049b510a8869b6f68cc841e7f8731364417af9
2016-11-07 14:37:56 -08:00
Emil Sjolander
ffb90e6ff2 Remove check for both modes being exact as this will never happen
Summary: css-layout will only call measure which it is unsure of the size of a node so it will never call measure with both modes equal to exact.

Reviewed By: dshahidehpour

Differential Revision: D4142193

fbshipit-source-id: fb8423cf0d45852ecb9df8fed042b25d1a443eea
2016-11-07 14:37:55 -08:00
Rachit Siamwalla
1c22a1aa53 Fix xplat CSSLayoutTests to compile on platforms without death tests.
Summary:
Not all platforms have gtest death tests. There is a define to check for that.
Bracketed the relevant tests with the define.

Reviewed By: youerkang

Differential Revision: D4141823

fbshipit-source-id: 1396657f3ee83853fcda85d5a51708d4e77642cb
2016-11-07 14:07:49 -08:00
Dustin Shahidehpour
7082734c6b Kill border API.
Summary: We don't want to expose this in our first usage. Lets kill it.

Reviewed By: emilsjolander

Differential Revision: D4140377

fbshipit-source-id: 0c53845ec65466692b847a5ce40c3b9823dd9557
2016-11-07 13:37:47 -08:00
Dustin Shahidehpour
366a61af8d Take care of pixel rounding for UIView.
Summary: You can lose a lot of performance on UIView's if they are not pixel-aligned. This protects it from happening in views which use css-layout.

Reviewed By: emilsjolander

Differential Revision: D4140306

fbshipit-source-id: 53493c08c084a7e3dcd4e05f6a665a99340ea5a6
2016-11-07 13:37:47 -08:00
安秋亮
18fe0959f0 Add inline definition for Microsoft Visual Studio
Summary:
The inline keyword is available only in C++. The __inline and __forceinline keywords are available in both C and C++. For compatibility with previous versions, _inline is a synonym for __inline.

https://msdn.microsoft.com/en-us/library/z8y1yy88(v=vs.120).aspx
Closes https://github.com/facebook/css-layout/pull/239

Reviewed By: astreet

Differential Revision: D4138941

Pulled By: emilsjolander

fbshipit-source-id: cb59dc91ef285e5378036c4912217fd4ec8d9f79
2016-11-07 13:07:40 -08:00
Dustin Shahidehpour
1ffce3edb1 Sanitize results from sizeThatFits:, fix bug where only one of the measure modes is CSSMeasureModeExactly.
Summary: As I've begun to integrate this into the codebase, I've found that sometimes our layouts are affected by bad implementations of sizeThatFits:. For example, in certain configurations of UILabel it won't take clipping into account and return a size that is much larger than the max size we requested. This adds some checks to make sure we never return a size that is larger than the one specified by `_measure`. This also fixes the bug where `CSSMeasureModeExactly` won't be applied if the measure mode for other parameter is node `CSSMeasureModeExactly`.

Reviewed By: emilsjolander

Differential Revision: D4131195

fbshipit-source-id: 4659fd83892a2c149b3b70733b06b19217507bf9
2016-11-07 06:52:47 -08:00
Andy Street
6165d7a2be Make CSSNode#measure final, cache more correct methodid
Summary:
@public

In the JNI portion of CSSLayout, there's a subtle bug where we were caching the jmethodid of the 'measure' of the first object that had measure called on it. However, if that class had overriden measure, then the jmethodid would be specific to that subclass's implementation and would not work for other classes. Conversely, if a regular CSSNode had been called first, then the super method would be called on the subclass instead of the proper overriden method.

Since there's not really a reason to overriden measure anyway (since you can just provide a different measure function), it's safest to just mark it final and explicitly cache the appropriate methodid

Reviewed By: emilsjolander

Differential Revision: D4132428

fbshipit-source-id: 6fb51597d80f1c03681e6611153b52b73b392245
2016-11-07 06:07:36 -08:00
Andy Street
01a3881426 Lazy create children list when first child is added
Summary:
@public

We don't need to allocate a list for every node since leaf nodes don't have children.

Reviewed By: emilsjolander

Differential Revision: D4130818

fbshipit-source-id: 80d3e98fce9d2daa0676fd1cbed0e81edcf7adb3
2016-11-07 05:52:41 -08:00
Andy Street
9c1896043d Assert that node can have measure function <==> node is a leaf node
Summary:
@public

Instead of silently ignorning non-leaf nodes with measure functions, we should assert that we don't create those kinds of trees.

Reviewed By: emilsjolander

Differential Revision: D4130770

fbshipit-source-id: a3ef10a2e63bbc12b5aa07977e4b84c8d59e3ffe
2016-11-07 05:37:45 -08:00
Dustin Shahidehpour
0f822bbef2 Remove overflow and flex from API.
Summary: flex is just shorthand for flexBasis, flexGrow and flexShrink, and I don't want to expose overflow yet, so, removing them from the API.

Reviewed By: ryanolsonk

Differential Revision: D4126773

fbshipit-source-id: e3b9ef714832cb5665bd20d7fa92f97a266c9210
2016-11-04 13:37:40 -07:00
Dustin Shahidehpour
e00e30ca15 Only mark Nodes dirty if an actual node is removed.
Summary: Currently, when we try to remove a child from a node, that node is mark dirty //regardless of whether or not anything was actually removed//. This fixes it.

Reviewed By: gkassabli

Differential Revision: D4125453

fbshipit-source-id: 745cfc55269415fea106a80c72401eb3074f2d31
2016-11-03 13:38:05 -07:00
Dustin Shahidehpour
b938017ccf Add Sizing API that doesn't change view's frame.
Summary: This exposes an API so people can find out the resulting size of a layout calculation without changing the frame of the view.

Reviewed By: emilsjolander

Differential Revision: D4124630

fbshipit-source-id: f2b28d8a5474857cb1c92e021a1f161806826cda
2016-11-03 13:07:37 -07:00
Georgiy Kassabli
630ae0972b Exposing layout cache check publicly
Summary: We need to expose CSSLayout caching check to CKFlexboxComponent to enable performant bridging to CKComponentKit

Reviewed By: emilsjolander

Differential Revision: D4124705

fbshipit-source-id: 23284967900585fa20dcb51c9cc1bee829b32975
2016-11-03 10:52:43 -07:00
Dustin Shahidehpour
d8662805d5 Fix incorrect results from css_usesFlexbox
Summary: With the current implementation, as long as you had set a value on usesFlexbox (YES or NO), it would return YES. This fixes it.

Reviewed By: amonshiz

Differential Revision: D4124485

fbshipit-source-id: 32fe4ec0109b5c8678a112f9d4295bd17a6f6dc2
2016-11-03 09:37:41 -07:00
Dustin Shahidehpour
26e7490fc9 Make CSSNodeRef readonly.
Summary: We don't want people to somehow change the underlying cnode on our CSSNodeBridge. Making it readonly.

Reviewed By: rnystrom

Differential Revision: D4124496

fbshipit-source-id: f88ed82c1df17d401aeca6f6341e429c95e55624
2016-11-03 09:07:37 -07:00
Dustin Shahidehpour
d94363ea7e Cleanup Measure method.
Summary: We have redundant/dead code in UIKit's sizing method, lets clean it up.

Reviewed By: emilsjolander

Differential Revision: D4110939

fbshipit-source-id: 35e856aa6c60fd24316bc67cc564f7eec2d9d714
2016-11-02 17:07:47 -07:00
Lukas Wöhrl
af5e6771d7 Prevent array out of bound access
Summary:
Even so the problem of #236 has been fixed via ced779b there is still a case where you have a out of bound array access of undefined behaviour. This PR prevents the out of bound access of the underlying c array. The out of bound access happens if you already have 4 subViews and add another one. Then you will access CSSNodeGetChild with 4 which points into uninitialized memory.
Closes https://github.com/facebook/css-layout/pull/237

Reviewed By: dshahidehpour

Differential Revision: D4107743

Pulled By: emilsjolander

fbshipit-source-id: 0f21397f3a77308369acfea7327733f74eb72e00
2016-11-01 20:54:00 -07:00
Dustin Shahidehpour
ced779b259 Prevent crash when accessing child count, but child list is NULL.
Summary: Previously, we would preallocate Node's with a child list of 4. We recently removed that logic (see diff below), and as a result, if you tried to access a Node's list of children before it had been allocated, you would crash. I added a simple check to protect from crashes, the operation of the check is O(1) so we shouldn't see a perf hit.

Reviewed By: emilsjolander

Differential Revision: D4104093

fbshipit-source-id: cd7b09818759aa76415b97e241f1a6746a2bc50c
2016-10-31 12:52:52 -07:00
Emil Sjolander
a65e6930cf Some small simplifications for function return values
Summary: Simplify logic for what value to return in smaller functions with a preference for ternary operator where possible.

Reviewed By: gkassabli

Differential Revision: D4101772

fbshipit-source-id: 626df10c0fc76278c330c86be4dc82fdda5f5156
2016-10-31 11:08:05 -07:00