/**
* 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<<9224a1489ee541a447ede3657538f5bc>>
package com.facebook.csslayout;
import static com.facebook.csslayout.CSSLayout.DIMENSION_HEIGHT;
import static com.facebook.csslayout.CSSLayout.DIMENSION_WIDTH;
import static com.facebook.csslayout.CSSLayout.POSITION_BOTTOM;
import static com.facebook.csslayout.CSSLayout.POSITION_LEFT;
import static com.facebook.csslayout.CSSLayout.POSITION_RIGHT;
import static com.facebook.csslayout.CSSLayout.POSITION_TOP;
/**
* Calculates layouts based on CSS style. See {@link #layoutNode(CSSNode, float, float)}.
*/
public class LayoutEngine {
private static final int CSS_FLEX_DIRECTION_COLUMN =
CSSFlexDirection.COLUMN.ordinal();
private static final int CSS_FLEX_DIRECTION_COLUMN_REVERSE =
CSSFlexDirection.COLUMN_REVERSE.ordinal();
private static final int CSS_FLEX_DIRECTION_ROW =
CSSFlexDirection.ROW.ordinal();
private static final int CSS_FLEX_DIRECTION_ROW_REVERSE =
CSSFlexDirection.ROW_REVERSE.ordinal();
private static final int CSS_POSITION_RELATIVE = CSSPositionType.RELATIVE.ordinal();
private static final int CSS_POSITION_ABSOLUTE = CSSPositionType.ABSOLUTE.ordinal();
private static final int[] leading = {
POSITION_TOP,
POSITION_BOTTOM,
POSITION_LEFT,
POSITION_RIGHT,
};
private static final int[] trailing = {
POSITION_BOTTOM,
POSITION_TOP,
POSITION_RIGHT,
POSITION_LEFT,
};
private static final int[] pos = {
POSITION_TOP,
POSITION_BOTTOM,
POSITION_LEFT,
POSITION_RIGHT,
};
private static final int[] dim = {
DIMENSION_HEIGHT,
DIMENSION_HEIGHT,
DIMENSION_WIDTH,
DIMENSION_WIDTH,
};
private static final int[] leadingSpacing = {
Spacing.TOP,
Spacing.BOTTOM,
Spacing.START,
Spacing.START
};
private static final int[] trailingSpacing = {
Spacing.BOTTOM,
Spacing.TOP,
Spacing.END,
Spacing.END
};
private static float boundAxis(CSSNode node, int axis, float value) {
float min = CSSConstants.UNDEFINED;
float max = CSSConstants.UNDEFINED;
if (axis == CSS_FLEX_DIRECTION_COLUMN ||
axis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
min = node.style.minHeight;
max = node.style.maxHeight;
} else if (axis == CSS_FLEX_DIRECTION_ROW ||
axis == CSS_FLEX_DIRECTION_ROW_REVERSE) {
min = node.style.minWidth;
max = node.style.maxWidth;
}
float boundValue = value;
if (!Float.isNaN(max) && max >= 0.0 && boundValue > max) {
boundValue = max;
}
if (!Float.isNaN(min) && min >= 0.0 && boundValue < min) {
boundValue = min;
}
return boundValue;
}
private static void setDimensionFromStyle(CSSNode node, int axis) {
// The parent already computed us a width or height. We just skip it
if (!Float.isNaN(node.layout.dimensions[dim[axis]])) {
return;
}
// We only run if there's a width or height defined
if (Float.isNaN(node.style.dimensions[dim[axis]]) ||
node.style.dimensions[dim[axis]] <= 0.0) {
return;
}
// The dimensions can never be smaller than the padding and border
float maxLayoutDimension = Math.max(
boundAxis(node, axis, node.style.dimensions[dim[axis]]),
node.style.padding.getWithFallback(leadingSpacing[axis], leading[axis]) +
node.style.padding.getWithFallback(trailingSpacing[axis], trailing[axis]) +
node.style.border.getWithFallback(leadingSpacing[axis], leading[axis]) +
node.style.border.getWithFallback(trailingSpacing[axis], trailing[axis]));
node.layout.dimensions[dim[axis]] = maxLayoutDimension;
}
private static float getRelativePosition(CSSNode node, int axis) {
float lead = node.style.position[leading[axis]];
if (!Float.isNaN(lead)) {
return lead;
}
float trailingPos = node.style.position[trailing[axis]];
return Float.isNaN(trailingPos) ? 0 : -trailingPos;
}
private static int resolveAxis(
int axis,
CSSDirection direction) {
if (direction == CSSDirection.RTL) {
if (axis == CSS_FLEX_DIRECTION_ROW) {
return CSS_FLEX_DIRECTION_ROW_REVERSE;
} else if (axis == CSS_FLEX_DIRECTION_ROW_REVERSE) {
return CSS_FLEX_DIRECTION_ROW;
}
}
return axis;
}
private static CSSDirection resolveDirection(CSSNode node, CSSDirection parentDirection) {
CSSDirection direction = node.style.direction;
if (direction == CSSDirection.INHERIT) {
direction = (parentDirection == null ? CSSDirection.LTR : parentDirection);
}
return direction;
}
private static int getFlexDirection(CSSNode node) {
return node.style.flexDirection.ordinal();
}
private static int getCrossFlexDirection(
int axis,
CSSDirection direction) {
if (axis == CSS_FLEX_DIRECTION_COLUMN ||
axis == CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
} else {
return CSS_FLEX_DIRECTION_COLUMN;
}
}
private static CSSAlign getAlignItem(CSSNode node, CSSNode child) {
if (child.style.alignSelf != CSSAlign.AUTO) {
return child.style.alignSelf;
}
return node.style.alignItems;
}
private static boolean isMeasureDefined(CSSNode node) {
return node.isMeasureDefined();
}
static boolean needsRelayout(CSSNode node, float parentMaxWidth, float parentMaxHeight) {
return node.isDirty() ||
!FloatUtil.floatsEqual(
node.lastLayout.requestedHeight,
node.layout.dimensions[DIMENSION_HEIGHT]) ||
!FloatUtil.floatsEqual(
node.lastLayout.requestedWidth,
node.layout.dimensions[DIMENSION_WIDTH]) ||
!FloatUtil.floatsEqual(node.lastLayout.parentMaxWidth, parentMaxWidth) ||
!FloatUtil.floatsEqual(node.lastLayout.parentMaxHeight, parentMaxHeight);
}
/*package*/ static void layoutNode(
CSSLayoutContext layoutContext,
CSSNode node,
float parentMaxWidth,
float parentMaxHeight,
CSSDirection parentDirection) {
if (needsRelayout(node, parentMaxWidth, parentMaxHeight)) {
node.lastLayout.requestedWidth = node.layout.dimensions[DIMENSION_WIDTH];
node.lastLayout.requestedHeight = node.layout.dimensions[DIMENSION_HEIGHT];
node.lastLayout.parentMaxWidth = parentMaxWidth;
node.lastLayout.parentMaxHeight = parentMaxHeight;
for (int i = 0, childCount = node.getChildCount(); i < childCount; i++) {
node.getChildAt(i).layout.resetResult();
}
layoutNodeImpl(layoutContext, node, parentMaxWidth, parentMaxHeight, parentDirection);
node.lastLayout.copy(node.layout);
} else {
node.layout.copy(node.lastLayout);
}
node.markHasNewLayout();
}
private static void layoutNodeImpl(
CSSLayoutContext layoutContext,
CSSNode node,
float parentMaxWidth,
float parentMaxHeight,
CSSDirection parentDirection) {
/** START_GENERATED **/
CSSDirection direction = resolveDirection(node, parentDirection);
int mainAxis = resolveAxis(getFlexDirection(node), direction);
int crossAxis = getCrossFlexDirection(mainAxis, direction);
int resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
// Handle width and height style attributes
setDimensionFromStyle(node, mainAxis);
setDimensionFromStyle(node, crossAxis);
// Set the resolved resolution in the node's layout
node.layout.direction = direction;
// The position is set by t
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
react-native-0.26.0-rc.zip (2000个子文件)
BUCK 867B
.buckconfig 221B
Layout.c 50KB
OnLoad.cpp 38KB
JSCExecutor.cpp 22KB
JSCExecutor.cpp 21KB
JSCTracing.cpp 14KB
JSCTracing.cpp 14KB
Exceptions.cpp 12KB
LocalString.cpp 9KB
Bridge.cpp 9KB
Bridge.cpp 9KB
JSCPerfLogging.cpp 8KB
fbjni.cpp 8KB
Instance.cpp 7KB
jscexecutor.cpp 7KB
jni_helpers.cpp 6KB
methodcall.cpp 4KB
Value.cpp 4KB
Value.cpp 4KB
JSCWebWorker.cpp 4KB
ModuleRegistry.cpp 4KB
ProxyExecutor.cpp 3KB
glog_init.cpp 3KB
JSLoader.cpp 3KB
JniJSModulesUnbundle.cpp 2KB
ByteBuffer.cpp 2KB
JSCLegacyProfiler.cpp 2KB
JSCLegacyProfiler.cpp 2KB
log.cpp 2KB
Countable.cpp 2KB
Hybrid.cpp 2KB
Environment.cpp 2KB
MethodCall.cpp 2KB
MethodCall.cpp 2KB
OnLoad.cpp 2KB
JSCHelpers.cpp 2KB
JSCHelpers.cpp 2KB
JSCPerfStats.cpp 2KB
JSCPerfStats.cpp 2KB
JMessageQueueThread.cpp 1KB
JSCMemory.cpp 1KB
JSCMemory.cpp 1KB
WeakReference.cpp 1KB
assert.cpp 1KB
JSLogging.cpp 1KB
jsclogging.cpp 1KB
value.cpp 1KB
References.cpp 919B
NativeArray.cpp 849B
ReferenceChecking.cpp 839B
OnLoad.cpp 644B
Platform.cpp 563B
JExecutorToken.cpp 530B
Platform.cpp 493B
react-native.css 20KB
style.css 1KB
.editorconfig 235B
.eslintrc 14KB
.eslintrc 39B
ReboundImage.gif 1.87MB
Rebound.gif 619KB
LayoutAnimationExample.gif 73KB
TweenState.gif 39KB
AnimationExperimentalScaleXY.gif 6KB
AnimationExperimentalOpacity.gif 4KB
.gitignore 79B
build.gradle 5KB
react.gradle 4KB
CoreClasses.h 21KB
References.h 20KB
CoreClasses-inl.h 19KB
Meta-inl.h 15KB
References-inl.h 14KB
Meta.h 11KB
log.h 9KB
RCTConvert.h 9KB
RCTBridgeModule.h 8KB
Hybrid.h 8KB
RCTImageLoader.h 8KB
RefPtr.h 7KB
RCTProfile.h 7KB
Registration-inl.h 7KB
RCTShadowView.h 6KB
FBSnapshotTestController.h 6KB
RCTBridge.h 6KB
Iterator-inl.h 6KB
Bridge.h 6KB
RCTUtils.h 6KB
JSCExecutor.h 5KB
JSCExecutor.h 5KB
RCTRootView.h 5KB
Bridge.h 5KB
RCTTestRunner.h 5KB
Value.h 5KB
Value.h 5KB
RCTAssert.h 5KB
config.h 5KB
Layout.h 5KB
RCTViewManager.h 5KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
a3737337
- 粉丝: 0
- 资源: 2869
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【小程序毕业设计】讲座预约系统微信小程序源码(完整前后端+mysql+说明文档+LW).zip
- 【小程序毕业设计】驾校报名小程序源码(完整前后端+mysql+说明文档+LW).zip
- 程序设计竞赛-在线判题系统(OJ系统)【含Web端+判题端】+项目源码+文档说明
- 大数据时代下短视频观看行为数据采集与分析的设计与实现
- 【小程序毕业设计】图书馆座位再利用系统源码(完整前后端+mysql+说明文档).zip
- 【小程序毕业设计】自习室预约系统源码(完整前后端+mysql+说明文档).zip
- 【小程序毕业设计】智能停车场管理系统源码(完整前后端+mysql+说明文档+LW).zip
- ssm练习项目-Java《基于ssm框架实现在线医院挂号系统》+项目源码+文档说明
- 【小程序毕业设计】游泳馆管理系统源码(完整前后端+mysql+说明文档+LW).zip
- 【小程序毕业设计】药店管理系统源码(完整前后端+mysql+说明文档).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功