Release React Native for Android

This is an early release and there are several things that are known
not to work if you're porting your iOS app to Android.

See the Known Issues guide on the website.

We will work with the community to reach platform parity with iOS.
This commit is contained in:
Martin Konicek
2015-09-14 15:35:58 +01:00
parent c372dab213
commit 42eb5464fd
571 changed files with 44550 additions and 116 deletions

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<0a1e3b1f834f027e7a5bc5303f945b0e>>
package com.facebook.csslayout;
public enum CSSAlign {
AUTO,
FLEX_START,
CENTER,
FLEX_END,
STRETCH,
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<755069c4747cc9fc5624d70e5130e3d1>>
package com.facebook.csslayout;
public class CSSConstants {
public static final float UNDEFINED = Float.NaN;
public static boolean isUndefined(float value) {
return Float.compare(value, UNDEFINED) == 0;
}
}

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<5dc7f205706089599859188712b3bd8a>>
package com.facebook.csslayout;
public enum CSSDirection {
INHERIT,
LTR,
RTL,
}

View File

@@ -0,0 +1,19 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<6183a87290f3acd1caef7b6301bbf3a7>>
package com.facebook.csslayout;
public enum CSSFlexDirection {
COLUMN,
COLUMN_REVERSE,
ROW,
ROW_REVERSE
}

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<619fbefba1cfee797bbc7dd18e22f50c>>
package com.facebook.csslayout;
public enum CSSJustify {
FLEX_START,
CENTER,
FLEX_END,
SPACE_BETWEEN,
SPACE_AROUND,
}

View File

@@ -0,0 +1,60 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<153b6759d2dd8fe8cf6d58a422450b96>>
package com.facebook.csslayout;
/**
* Where the output of {@link LayoutEngine#layoutNode(CSSNode, float)} will go in the CSSNode.
*/
public class CSSLayout {
public float top;
public float left;
public float right;
public float bottom;
public float width = CSSConstants.UNDEFINED;
public float height = CSSConstants.UNDEFINED;
public CSSDirection direction = CSSDirection.LTR;
/**
* This should always get called before calling {@link LayoutEngine#layoutNode(CSSNode, float)}
*/
public void resetResult() {
left = 0;
top = 0;
right = 0;
bottom = 0;
width = CSSConstants.UNDEFINED;
height = CSSConstants.UNDEFINED;
direction = CSSDirection.LTR;
}
public void copy(CSSLayout layout) {
left = layout.left;
top = layout.top;
right = layout.right;
bottom = layout.bottom;
width = layout.width;
height = layout.height;
direction = layout.direction;
}
@Override
public String toString() {
return "layout: {" +
"left: " + left + ", " +
"top: " + top + ", " +
"width: " + width + ", " +
"height: " + height +
"direction: " + direction +
"}";
}
}

View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<9d48f3d4330e7b6cba0fff7d8f1e8b0c>>
package com.facebook.csslayout;
/**
* A context for holding values local to a given instance of layout computation.
*
* This is necessary for making layout thread-safe. A separate instance should
* be used when {@link CSSNode#calculateLayout} is called concurrently on
* different node hierarchies.
*/
public class CSSLayoutContext {
/*package*/ final MeasureOutput measureOutput = new MeasureOutput();
}

View File

@@ -0,0 +1,396 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<c3a1298e36789dcda4cc2776d48646a7>>
package com.facebook.csslayout;
import javax.annotation.Nullable;
import java.util.ArrayList;
import com.facebook.infer.annotation.Assertions;
/**
* A CSS Node. It has a style object you can manipulate at {@link #style}. After calling
* {@link #calculateLayout()}, {@link #layout} will be filled with the results of the layout.
*/
public class CSSNode {
private static enum LayoutState {
/**
* Some property of this node or its children has changes and the current values in
* {@link #layout} are not valid.
*/
DIRTY,
/**
* This node has a new layout relative to the last time {@link #markLayoutSeen()} was called.
*/
HAS_NEW_LAYOUT,
/**
* {@link #layout} is valid for the node's properties and this layout has been marked as
* having been seen.
*/
UP_TO_DATE,
}
public static interface MeasureFunction {
/**
* Should measure the given node and put the result in the given MeasureOutput.
*
* NB: measure is NOT guaranteed to be threadsafe/re-entrant safe!
*/
public void measure(CSSNode node, float width, MeasureOutput measureOutput);
}
// VisibleForTesting
/*package*/ final CSSStyle style = new CSSStyle();
/*package*/ final CSSLayout layout = new CSSLayout();
/*package*/ final CachedCSSLayout lastLayout = new CachedCSSLayout();
public int lineIndex = 0;
private @Nullable ArrayList<CSSNode> mChildren;
private @Nullable CSSNode mParent;
private @Nullable MeasureFunction mMeasureFunction = null;
private LayoutState mLayoutState = LayoutState.DIRTY;
public int getChildCount() {
return mChildren == null ? 0 : mChildren.size();
}
public CSSNode getChildAt(int i) {
Assertions.assertNotNull(mChildren);
return mChildren.get(i);
}
public void addChildAt(CSSNode child, int i) {
if (child.mParent != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first.");
}
if (mChildren == null) {
// 4 is kinda arbitrary, but the default of 10 seems really high for an average View.
mChildren = new ArrayList<>(4);
}
mChildren.add(i, child);
child.mParent = this;
dirty();
}
public CSSNode removeChildAt(int i) {
Assertions.assertNotNull(mChildren);
CSSNode removed = mChildren.remove(i);
removed.mParent = null;
dirty();
return removed;
}
public @Nullable CSSNode getParent() {
return mParent;
}
/**
* @return the index of the given child, or -1 if the child doesn't exist in this node.
*/
public int indexOf(CSSNode child) {
Assertions.assertNotNull(mChildren);
return mChildren.indexOf(child);
}
public void setMeasureFunction(MeasureFunction measureFunction) {
if (!valuesEqual(mMeasureFunction, measureFunction)) {
mMeasureFunction = measureFunction;
dirty();
}
}
public boolean isMeasureDefined() {
return mMeasureFunction != null;
}
/*package*/ MeasureOutput measure(MeasureOutput measureOutput, float width) {
if (!isMeasureDefined()) {
throw new RuntimeException("Measure function isn't defined!");
}
measureOutput.height = CSSConstants.UNDEFINED;
measureOutput.width = CSSConstants.UNDEFINED;
Assertions.assertNotNull(mMeasureFunction).measure(this, width, measureOutput);
return measureOutput;
}
/**
* Performs the actual layout and saves the results in {@link #layout}
*/
public void calculateLayout(CSSLayoutContext layoutContext) {
layout.resetResult();
LayoutEngine.layoutNode(layoutContext, this, CSSConstants.UNDEFINED, null);
}
/**
* See {@link LayoutState#DIRTY}.
*/
protected boolean isDirty() {
return mLayoutState == LayoutState.DIRTY;
}
/**
* See {@link LayoutState#HAS_NEW_LAYOUT}.
*/
public boolean hasNewLayout() {
return mLayoutState == LayoutState.HAS_NEW_LAYOUT;
}
protected void dirty() {
if (mLayoutState == LayoutState.DIRTY) {
return;
} else if (mLayoutState == LayoutState.HAS_NEW_LAYOUT) {
throw new IllegalStateException("Previous layout was ignored! markLayoutSeen() never called");
}
mLayoutState = LayoutState.DIRTY;
if (mParent != null) {
mParent.dirty();
}
}
/*package*/ void markHasNewLayout() {
mLayoutState = LayoutState.HAS_NEW_LAYOUT;
}
/**
* Tells the node that the current values in {@link #layout} have been seen. Subsequent calls
* to {@link #hasNewLayout()} will return false until this node is laid out with new parameters.
* You must call this each time the layout is generated if the node has a new layout.
*/
public void markLayoutSeen() {
if (!hasNewLayout()) {
throw new IllegalStateException("Expected node to have a new layout to be seen!");
}
mLayoutState = LayoutState.UP_TO_DATE;
}
private void toStringWithIndentation(StringBuilder result, int level) {
// Spaces and tabs are dropped by IntelliJ logcat integration, so rely on __ instead.
StringBuilder indentation = new StringBuilder();
for (int i = 0; i < level; ++i) {
indentation.append("__");
}
result.append(indentation.toString());
result.append(layout.toString());
if (getChildCount() == 0) {
return;
}
result.append(", children: [\n");
for (int i = 0; i < getChildCount(); i++) {
getChildAt(i).toStringWithIndentation(result, level + 1);
result.append("\n");
}
result.append(indentation + "]");
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
this.toStringWithIndentation(sb, 0);
return sb.toString();
}
protected boolean valuesEqual(float f1, float f2) {
return FloatUtil.floatsEqual(f1, f2);
}
protected <T> boolean valuesEqual(@Nullable T o1, @Nullable T o2) {
if (o1 == null) {
return o2 == null;
}
return o1.equals(o2);
}
public void setDirection(CSSDirection direction) {
if (!valuesEqual(style.direction, direction)) {
style.direction = direction;
dirty();
}
}
public void setFlexDirection(CSSFlexDirection flexDirection) {
if (!valuesEqual(style.flexDirection, flexDirection)) {
style.flexDirection = flexDirection;
dirty();
}
}
public void setJustifyContent(CSSJustify justifyContent) {
if (!valuesEqual(style.justifyContent, justifyContent)) {
style.justifyContent = justifyContent;
dirty();
}
}
public void setAlignItems(CSSAlign alignItems) {
if (!valuesEqual(style.alignItems, alignItems)) {
style.alignItems = alignItems;
dirty();
}
}
public void setAlignSelf(CSSAlign alignSelf) {
if (!valuesEqual(style.alignSelf, alignSelf)) {
style.alignSelf = alignSelf;
dirty();
}
}
public void setPositionType(CSSPositionType positionType) {
if (!valuesEqual(style.positionType, positionType)) {
style.positionType = positionType;
dirty();
}
}
public void setWrap(CSSWrap flexWrap) {
if (!valuesEqual(style.flexWrap, flexWrap)) {
style.flexWrap = flexWrap;
dirty();
}
}
public void setFlex(float flex) {
if (!valuesEqual(style.flex, flex)) {
style.flex = flex;
dirty();
}
}
public void setMargin(int spacingType, float margin) {
if (style.margin.set(spacingType, margin)) {
dirty();
}
}
public void setPadding(int spacingType, float padding) {
if (style.padding.set(spacingType, padding)) {
dirty();
}
}
public void setBorder(int spacingType, float border) {
if (style.border.set(spacingType, border)) {
dirty();
}
}
public void setPositionTop(float positionTop) {
if (!valuesEqual(style.positionTop, positionTop)) {
style.positionTop = positionTop;
dirty();
}
}
public void setPositionBottom(float positionBottom) {
if (!valuesEqual(style.positionBottom, positionBottom)) {
style.positionBottom = positionBottom;
dirty();
}
}
public void setPositionLeft(float positionLeft) {
if (!valuesEqual(style.positionLeft, positionLeft)) {
style.positionLeft = positionLeft;
dirty();
}
}
public void setPositionRight(float positionRight) {
if (!valuesEqual(style.positionRight, positionRight)) {
style.positionRight = positionRight;
dirty();
}
}
public void setStyleWidth(float width) {
if (!valuesEqual(style.width, width)) {
style.width = width;
dirty();
}
}
public void setStyleHeight(float height) {
if (!valuesEqual(style.height, height)) {
style.height = height;
dirty();
}
}
public float getLayoutX() {
return layout.left;
}
public float getLayoutY() {
return layout.top;
}
public float getLayoutWidth() {
return layout.width;
}
public float getLayoutHeight() {
return layout.height;
}
public CSSDirection getLayoutDirection() {
return layout.direction;
}
/**
* Get this node's padding, as defined by style + default padding.
*/
public Spacing getStylePadding() {
return style.padding;
}
/**
* Get this node's width, as defined in the style.
*/
public float getStyleWidth() {
return style.width;
}
/**
* Get this node's height, as defined in the style.
*/
public float getStyleHeight() {
return style.height;
}
/**
* Get this node's direction, as defined in the style.
*/
public CSSDirection getStyleDirection() {
return style.direction;
}
/**
* Set a default padding (left/top/right/bottom) for this node.
*/
public void setDefaultPadding(int spacingType, float padding) {
if (style.padding.setDefault(spacingType, padding)) {
dirty();
}
}
}

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<a53da9b13bd6e7b03fd743adf0e536b3>>
package com.facebook.csslayout;
public enum CSSPositionType {
RELATIVE,
ABSOLUTE,
}

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<ec76950a22dda1c6e98eafc15ccf7cd3>>
package com.facebook.csslayout;
/**
* The CSS style definition for a {@link CSSNode}.
*/
public class CSSStyle {
public CSSDirection direction = CSSDirection.INHERIT;
public CSSFlexDirection flexDirection = CSSFlexDirection.COLUMN;
public CSSJustify justifyContent = CSSJustify.FLEX_START;
public CSSAlign alignContent = CSSAlign.FLEX_START;
public CSSAlign alignItems = CSSAlign.STRETCH;
public CSSAlign alignSelf = CSSAlign.AUTO;
public CSSPositionType positionType = CSSPositionType.RELATIVE;
public CSSWrap flexWrap = CSSWrap.NOWRAP;
public float flex;
public Spacing margin = new Spacing();
public Spacing padding = new Spacing();
public Spacing border = new Spacing();
public float positionTop = CSSConstants.UNDEFINED;
public float positionBottom = CSSConstants.UNDEFINED;
public float positionLeft = CSSConstants.UNDEFINED;
public float positionRight = CSSConstants.UNDEFINED;
public float width = CSSConstants.UNDEFINED;
public float height = CSSConstants.UNDEFINED;
public float minWidth = CSSConstants.UNDEFINED;
public float minHeight = CSSConstants.UNDEFINED;
public float maxWidth = CSSConstants.UNDEFINED;
public float maxHeight = CSSConstants.UNDEFINED;
}

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<21dab9bd1acf5892ad09370b69b7dd71>>
package com.facebook.csslayout;
public enum CSSWrap {
NOWRAP,
WRAP,
}

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<8276834951a75286a0b6d4a980bc43ce>>
package com.facebook.csslayout;
/**
* CSSLayout with additional information about the conditions under which it was generated.
* {@link #requestedWidth} and {@link #requestedHeight} are the width and height the parent set on
* this node before calling layout visited us.
*/
public class CachedCSSLayout extends CSSLayout {
public float requestedWidth = CSSConstants.UNDEFINED;
public float requestedHeight = CSSConstants.UNDEFINED;
public float parentMaxWidth = CSSConstants.UNDEFINED;
}

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<fc074ec7db63f2eebf1e9cbc626f280d>>
package com.facebook.csslayout;
public class FloatUtil {
private static final float EPSILON = .00001f;
public static boolean floatsEqual(float f1, float f2) {
if (Float.isNaN(f1) || Float.isNaN(f2)) {
return Float.isNaN(f1) && Float.isNaN(f2);
}
return Math.abs(f2 - f1) < EPSILON;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<177254872216bd05e2c0667dc29ef032>>
package com.facebook.csslayout;
/**
* POJO to hold the output of the measure function.
*/
public class MeasureOutput {
public float width;
public float height;
}

View File

@@ -0,0 +1,12 @@
The source of truth for css-layout is: https://github.com/facebook/css-layout
The code here should be kept in sync with GitHub.
HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/7104f7c8eb6c160a8d10badc08f9b981bb65e19c
There is generated code in:
- README (this file)
- java/com/facebook/csslayout (this folder)
- javatests/com/facebook/csslayout
The code was generated by running 'make' in the css-layout folder and copied to React Native.

View File

@@ -0,0 +1,14 @@
The source of truth for css-layout is: https://github.com/facebook/css-layout
The code here should be kept in sync with GitHub.
HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/7104f7c8eb6c160a8d10badc08f9b981bb65e19c
There is generated code in:
- README.facebook (this file)
- java/com/facebook/csslayout (this folder)
- javatests/com/facebook/csslayout
The code was generated by running 'make' in the css-layout folder and running:
./syncFromGithub.sh <pathToGithubRepo> <pathToFbAndroid>

View File

@@ -0,0 +1,162 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// NOTE: this file is auto-copied from https://github.com/facebook/css-layout
// @generated SignedSource<<6853e87a84818f1abb6573aee7d6bd55>>
package com.facebook.csslayout;
import javax.annotation.Nullable;
/**
* Class representing CSS spacing (padding, margin, and borders). This is mostly necessary to
* properly implement interactions and updates for properties like margin, marginLeft, and
* marginHorizontal.
*/
public class Spacing {
/**
* Spacing type that represents the left direction. E.g. {@code marginLeft}.
*/
public static final int LEFT = 0;
/**
* Spacing type that represents the top direction. E.g. {@code marginTop}.
*/
public static final int TOP = 1;
/**
* Spacing type that represents the right direction. E.g. {@code marginRight}.
*/
public static final int RIGHT = 2;
/**
* Spacing type that represents the bottom direction. E.g. {@code marginBottom}.
*/
public static final int BOTTOM = 3;
/**
* Spacing type that represents vertical direction (top and bottom). E.g. {@code marginVertical}.
*/
public static final int VERTICAL = 4;
/**
* Spacing type that represents horizontal direction (left and right). E.g.
* {@code marginHorizontal}.
*/
public static final int HORIZONTAL = 5;
/**
* Spacing type that represents start direction e.g. left in left-to-right, right in right-to-left.
*/
public static final int START = 6;
/**
* Spacing type that represents end direction e.g. right in left-to-right, left in right-to-left.
*/
public static final int END = 7;
/**
* Spacing type that represents all directions (left, top, right, bottom). E.g. {@code margin}.
*/
public static final int ALL = 8;
private final float[] mSpacing = newFullSpacingArray();
@Nullable private float[] mDefaultSpacing = null;
/**
* Set a spacing value.
*
* @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM},
* {@link #VERTICAL}, {@link #HORIZONTAL}, {@link #ALL}
* @param value the value for this direction
* @return {@code true} if the spacing has changed, or {@code false} if the same value was already
* set
*/
public boolean set(int spacingType, float value) {
if (!FloatUtil.floatsEqual(mSpacing[spacingType], value)) {
mSpacing[spacingType] = value;
return true;
}
return false;
}
/**
* Set a default spacing value. This is used as a fallback when no spacing has been set for a
* particular direction.
*
* @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}
* @param value the default value for this direction
* @return
*/
public boolean setDefault(int spacingType, float value) {
if (mDefaultSpacing == null) {
mDefaultSpacing = newSpacingResultArray();
}
if (!FloatUtil.floatsEqual(mDefaultSpacing[spacingType], value)) {
mDefaultSpacing[spacingType] = value;
return true;
}
return false;
}
/**
* Get the spacing for a direction. This takes into account any default values that have been set.
*
* @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}
*/
public float get(int spacingType) {
int secondType = spacingType == TOP || spacingType == BOTTOM ? VERTICAL : HORIZONTAL;
float defaultValue = spacingType == START || spacingType == END ? CSSConstants.UNDEFINED : 0;
return
!CSSConstants.isUndefined(mSpacing[spacingType])
? mSpacing[spacingType]
: !CSSConstants.isUndefined(mSpacing[secondType])
? mSpacing[secondType]
: !CSSConstants.isUndefined(mSpacing[ALL])
? mSpacing[ALL]
: mDefaultSpacing != null
? mDefaultSpacing[spacingType]
: defaultValue;
}
/**
* Get the raw value (that was set using {@link #set(int, float)}), without taking into account
* any default values.
*
* @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM},
* {@link #VERTICAL}, {@link #HORIZONTAL}, {@link #ALL}
*/
public float getRaw(int spacingType) {
return mSpacing[spacingType];
}
private static float[] newFullSpacingArray() {
return new float[] {
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
};
}
private static float[] newSpacingResultArray() {
return newSpacingResultArray(0);
}
private static float[] newSpacingResultArray(float defaultValue) {
return new float[] {
defaultValue,
defaultValue,
defaultValue,
defaultValue,
defaultValue,
defaultValue,
CSSConstants.UNDEFINED,
CSSConstants.UNDEFINED,
defaultValue,
};
}
}

View File

@@ -0,0 +1,99 @@
#!/usr/bin/env bash
function usage {
echo "usage: syncFromGithub.sh <pathToGithubRepo> <pathToFbAndroidRepo>";
}
function patchfile {
# Add React Native copyright
printf "/**\n" >> /tmp/csslayoutsync.tmp
printf " * Copyright (c) 2014-present, Facebook, Inc.\n" >> /tmp/csslayoutsync.tmp
printf " * All rights reserved.\n" >> /tmp/csslayoutsync.tmp
printf " * This source code is licensed under the BSD-style license found in the\n" >> /tmp/csslayoutsync.tmp
printf " * LICENSE file in the root directory of this source tree. An additional grant\n" >> /tmp/csslayoutsync.tmp
printf " * of patent rights can be found in the PATENTS file in the same directory.\n" >> /tmp/csslayoutsync.tmp
printf " */\n\n" >> /tmp/csslayoutsync.tmp
printf "// NOTE: this file is auto-copied from https://github.com/facebook/css-layout\n" >> /tmp/csslayoutsync.tmp
# The following is split over four lines so Phabricator doesn't think this file is generated
printf "// @g" >> /tmp/csslayoutsync.tmp
printf "enerated <<S" >> /tmp/csslayoutsync.tmp
printf "ignedSource::*O*zOeWoEQle#+L" >> /tmp/csslayoutsync.tmp
printf "!plEphiEmie@IsG>>\n\n" >> /tmp/csslayoutsync.tmp
tail -n +9 $1 >> /tmp/csslayoutsync.tmp
mv /tmp/csslayoutsync.tmp $1
$ROOT/scripts/signedsource.py sign $1
}
if [ -z $1 ]; then
usage
exit 1
fi
if [ -z $2 ]; then
usage
exit 1
fi
GITHUB=$1
ROOT=$2
set -e # exit if any command fails
echo "Making github project..."
pushd $GITHUB
COMMIT_ID=$(git rev-parse HEAD)
make
popd
SRC=$GITHUB/src/java/src/com/facebook/csslayout
TESTS=$GITHUB/src/java/tests/com/facebook/csslayout
FBA_SRC=.
FBA_TESTS=$ROOT/javatests/com/facebook/csslayout
echo "Copying src files over..."
cp $SRC/*.java $FBA_SRC
echo "Copying test files over..."
cp $TESTS/*.java $FBA_TESTS
echo "Patching files..."
for sourcefile in $FBA_SRC/*.java; do
patchfile $sourcefile
done
for testfile in $FBA_TESTS/*.java; do
patchfile $testfile
done
echo "Writing README.facebook"
echo "The source of truth for css-layout is: https://github.com/facebook/css-layout
The code here should be kept in sync with GitHub.
HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/$COMMIT_ID
There is generated code in:
- README.facebook (this file)
- java/com/facebook/csslayout (this folder)
- javatests/com/facebook/csslayout
The code was generated by running 'make' in the css-layout folder and running:
./syncFromGithub.sh <pathToGithubRepo> <pathToFbAndroid>
" > $FBA_SRC/README.facebook
echo "Writing README"
echo "The source of truth for css-layout is: https://github.com/facebook/css-layout
The code here should be kept in sync with GitHub.
HEAD at the time this code was synced: https://github.com/facebook/css-layout/commit/$COMMIT_ID
There is generated code in:
- README (this file)
- java/com/facebook/csslayout (this folder)
- javatests/com/facebook/csslayout
The code was generated by running 'make' in the css-layout folder and copied to React Native.
" > $FBA_SRC/README
echo "Done."
echo "Please run buck test //javatests/com/facebook/csslayout"