Skip to content

Commit

Permalink
Fix presubmit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jswong65 authored and jafu888 committed Sep 21, 2022
1 parent 981d408 commit b8993a3
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private fun FlowComposableTest(
constraintSet = ConstraintSet(
"""
{
flow1: {
flow1: {
width: $width,
height: $height,
type: '$type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MotionFlowTest {
{
ConstraintSets: {
start: {
flow1: {
flow1: {
width: 'parent',
height: 'parent',
type: 'hFlow',
Expand All @@ -83,9 +83,8 @@ class MotionFlowTest {
contains: ['1', '2', '3', '4'],
}
},
end: {
flow2: {
flow2: {
width: 'parent',
height: 'parent',
type: 'vFlow',
Expand All @@ -96,7 +95,6 @@ class MotionFlowTest {
}
}
},
Transitions: {
default: {
from: 'start', to: 'end',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import kotlinx.coroutines.launch
* Use [rememberMotionContent] and [MotionScope.motion] to animate layout changes caused by changing
* the Composable's Layout parent on state changes.
*
* E.g:
* E.g.:
*
* ```
* var vertOrHor by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -225,7 +225,7 @@ class MotionScope(
update(endWidget, 1)
}
}
// TODO: Optimize all animated items at a time under a single Animatable. E.g: If after
// TODO: Optimize all animated items at a time under a single Animatable. E.g.: If after
// a state change, 10 different items changed, animate them using one Animatable
// object, as opposed to running 10 separate Animatables doing the same thing,
// measure/layout calls in the LookAheadLayout MeasurePolicy might provide the clue to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ import androidx.constraintlayout.compose.carousel.carouselSwipeable
*/
@OptIn(ExperimentalMotionApi::class)
@Composable
@Suppress("UnavailableSymbol")
fun MotionCarousel(
@Suppress("HiddenTypeParameter")
motionScene: MotionScene,
initialSlotIndex: Int,
numSlots: Int,
Expand Down Expand Up @@ -238,7 +240,7 @@ fun MotionCarousel(
MotionLayout(motionScene = motionScene,
transitionName = transitionName.value,
progress = mprogress,
motionLayoutFlags = MotionLayoutFlags.FullMeasure, // TODO: only apply as needed
motionLayoutFlags = setOf(MotionLayoutFlag.FullMeasure), // TODO: only apply as needed
modifier = Modifier
.fillMaxSize()
.background(Color.White)
Expand Down Expand Up @@ -319,8 +321,10 @@ interface MotionCarouselScope {
)

@OptIn(ExperimentalMotionApi::class)
@Suppress("UnavailableSymbol")
fun itemsWithProperties(
count: Int,
@Suppress("HiddenTypeParameter")
itemContent: @Composable (
index: Int,
properties: androidx.compose.runtime.State<MotionProperties>
Expand All @@ -329,8 +333,10 @@ interface MotionCarouselScope {
}

@OptIn(ExperimentalMotionApi::class)
@Suppress("UnavailableSymbol")
inline fun <T> MotionCarouselScope.itemsWithProperties(
items: List<T>,
@Suppress("HiddenTypeParameter")
crossinline itemContent: @Composable (
item: T,
properties: androidx.compose.runtime.State<MotionProperties>
Expand All @@ -351,9 +357,12 @@ private fun rememberStateOfItemsProvider(

@OptIn(ExperimentalMotionApi::class)
interface MotionItemsProvider {
@SuppressWarnings("UnavailableSymbol")
fun getContent(index: Int): @Composable() () -> Unit
@SuppressWarnings("UnavailableSymbol")
fun getContent(
index: Int,
@SuppressWarnings("HiddenTypeParameter")
properties: androidx.compose.runtime.State<MotionProperties>
): @Composable() () -> Unit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import kotlinx.coroutines.launch
/**
* Measure flags for MotionLayout
*/
enum class MotionLayoutFlags(value: Long) {
enum class MotionLayoutFlag(@Suppress("UNUSED_PARAMETER") value: Long) {
Default(0),
FullMeasure(1)
}
Expand All @@ -71,7 +71,7 @@ inline fun MotionLayout(
progress: Float,
debug: EnumSet<MotionLayoutDebugFlags> = EnumSet.of(MotionLayoutDebugFlags.NONE),
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
crossinline content: @Composable MotionLayoutScope.() -> Unit
) {
val motionProgress = createAndUpdateMotionProgress(progress = progress)
Expand Down Expand Up @@ -103,7 +103,7 @@ inline fun MotionLayout(
transitionName: String = "default",
debug: EnumSet<MotionLayoutDebugFlags> = EnumSet.of(MotionLayoutDebugFlags.NONE),
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
crossinline content: @Composable (MotionLayoutScope.() -> Unit),
) {
MotionLayoutCore(
Expand Down Expand Up @@ -139,7 +139,7 @@ inline fun MotionLayout(
animationSpec: AnimationSpec<Float> = tween(),
debug: EnumSet<MotionLayoutDebugFlags> = EnumSet.of(MotionLayoutDebugFlags.NONE),
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
noinline finishedAnimationListener: (() -> Unit)? = null,
crossinline content: @Composable (MotionLayoutScope.() -> Unit)
) {
Expand Down Expand Up @@ -168,7 +168,7 @@ inline fun MotionLayout(
debug: EnumSet<MotionLayoutDebugFlags> = EnumSet.of(MotionLayoutDebugFlags.NONE),
informationReceiver: LayoutInformationReceiver? = null,
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
crossinline content: @Composable (MotionLayoutScope.() -> Unit)
) {
val motionProgress = createAndUpdateMotionProgress(progress = progress)
Expand All @@ -189,15 +189,18 @@ inline fun MotionLayout(
@ExperimentalMotionApi
@PublishedApi
@Composable
@Suppress("UnavailableSymbol")
internal inline fun MotionLayoutCore(
@Suppress("HiddenTypeParameter")
motionScene: MotionScene,
modifier: Modifier = Modifier,
constraintSetName: String? = null,
animationSpec: AnimationSpec<Float> = tween(),
debugFlag: MotionLayoutDebugFlags = MotionLayoutDebugFlags.NONE,
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
noinline finishedAnimationListener: (() -> Unit)? = null,
@Suppress("HiddenTypeParameter")
crossinline content: @Composable (MotionLayoutScope.() -> Unit)
) {
val needsUpdate = remember {
Expand Down Expand Up @@ -285,14 +288,17 @@ internal inline fun MotionLayoutCore(
@ExperimentalMotionApi
@PublishedApi
@Composable
@Suppress("UnavailableSymbol")
internal inline fun MotionLayoutCore(
@Suppress("HiddenTypeParameter")
motionScene: MotionScene,
progress: Float,
modifier: Modifier = Modifier,
debug: EnumSet<MotionLayoutDebugFlags> = EnumSet.of(MotionLayoutDebugFlags.NONE),
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
transitionName: String,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
@Suppress("HiddenTypeParameter")
crossinline content: @Composable MotionLayoutScope.() -> Unit,
) {
val transition = remember(motionScene, transitionName) {
Expand Down Expand Up @@ -328,6 +334,7 @@ internal inline fun MotionLayoutCore(
@ExperimentalMotionApi
@PublishedApi
@Composable
@Suppress("UnavailableSymbol")
internal inline fun MotionLayoutCore(
start: ConstraintSet,
end: ConstraintSet,
Expand All @@ -337,7 +344,8 @@ internal inline fun MotionLayoutCore(
debugFlag: MotionLayoutDebugFlags = MotionLayoutDebugFlags.NONE,
informationReceiver: LayoutInformationReceiver? = null,
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
@Suppress("HiddenTypeParameter")
crossinline content: @Composable MotionLayoutScope.() -> Unit
) {
// TODO: Merge this snippet with UpdateWithForcedIfNoUserChange
Expand Down Expand Up @@ -422,12 +430,15 @@ inline fun MotionLayout(
@PublishedApi
@ExperimentalMotionApi
@Composable
@Suppress("UnavailableSymbol")
internal inline fun MotionLayoutCore(
modifier: Modifier = Modifier,
optimizationLevel: Int = Optimizer.OPTIMIZATION_STANDARD,
motionLayoutState: MotionLayoutStateImpl,
@Suppress("HiddenTypeParameter")
motionScene: MotionScene,
transitionName: String = "default",
@Suppress("HiddenTypeParameter")
crossinline content: @Composable MotionLayoutScope.() -> Unit
) {
val transition = remember(motionScene, transitionName) {
Expand Down Expand Up @@ -460,10 +471,10 @@ internal inline fun MotionLayoutCore(
)
}

@Suppress("unused")
@LayoutScopeMarker
@ExperimentalMotionApi
class MotionLayoutScope @PublishedApi internal constructor(
class MotionLayoutScope @Suppress("ShowingMemberInHiddenClass")
@PublishedApi internal constructor(
private val measurer: MotionMeasurer,
private val motionProgress: MotionProgress
) {
Expand Down Expand Up @@ -554,7 +565,7 @@ internal fun rememberMotionLayoutMeasurePolicy(
constraintSetEnd: ConstraintSet,
@SuppressWarnings("HiddenTypeParameter") transition: TransitionImpl?,
motionProgress: MotionProgress,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
measurer: MotionMeasurer
): MeasurePolicy {
val density = LocalDensity.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ internal class MotionMeasurer : Measurer() {
root.measure(Optimizer.OPTIMIZATION_NONE, 0, 0, 0, 0, 0, 0, 0, 0)
}

@Suppress("UnavailableSymbol")
fun performInterpolationMeasure(
constraints: Constraints,
layoutDirection: LayoutDirection,
Expand All @@ -86,16 +87,17 @@ internal class MotionMeasurer : Measurer() {
measurables: List<Measurable>,
optimizationLevel: Int,
progress: Float,
motionLayoutFlags: MotionLayoutFlags = MotionLayoutFlags.Default,
motionLayoutFlags: Set<MotionLayoutFlag> = setOf<MotionLayoutFlag>(),
measureScope: MeasureScope
): IntSize {
this.density = measureScope
this.measureScope = measureScope

var needsRemeasure = false
if (motionLayoutFlags == MotionLayoutFlags.Default) {
var flag = motionLayoutFlags.firstOrNull()
if (flag == MotionLayoutFlag.Default || flag == null) {
needsRemeasure = needsRemeasure(constraints)
} else if (motionLayoutFlags == MotionLayoutFlags.FullMeasure) {
} else if (flag == MotionLayoutFlag.FullMeasure) {
needsRemeasure = true
}

Expand Down Expand Up @@ -511,6 +513,7 @@ internal class MotionMeasurer : Measurer() {
frameCache.clear()
}

@Suppress("UnavailableSymbol")
fun initWith(
start: ConstraintSet,
end: ConstraintSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ internal class MotionSceneDslImpl(
/**
* Scope used by the MotionScene DSL.
*
* &nbsp
* &nbsp;
*
* Define new [ConstraintSet]s and [Transition]s within this scope using [constraintSet] and
* [transition] respectively.
*
* Alternatively, you may add existing objects to this scope using [addConstraintSet] and
* [addTransition].
*
* &nbsp
* &nbsp;
*
* The [defaultTransition] **should always be set**. It defines the initial state of the layout and
* works as a fallback for undefined `from -> to` transitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void reset() {
* Create a copy of the statistics
* @return a copy
*/
@Override
public ConstraintLayoutStatistics clone() {
return new ConstraintLayoutStatistics(this);
}
Expand Down Expand Up @@ -122,10 +123,10 @@ public void logSummary(String tag) {

@SuppressLint({"LogConditional"})
private void log(String tag) {
String value;
StackTraceElement s = new Throwable().getStackTrace()[2];

Log.v(tag, "CL Perf: -------- Performance .(" + s.getFileName() + ":" + s.getLineNumber() + ") ------ ");
Log.v(tag, "CL Perf: -------- Performance .(" +
s.getFileName() + ":" + s.getLineNumber() + ") ------ ");

DecimalFormat df = new DecimalFormat("###.000");

Expand Down Expand Up @@ -172,7 +173,8 @@ private String log(int param) {
}

/**
* Generate a float formatted String for the parameter comparing current value with value in relative
* Generate a float formatted String for the parameter comparing
* current value with value in relative
* @param df Format the float using this
* @param relative compare against
* @param param the parameter to compare
Expand Down Expand Up @@ -218,7 +220,8 @@ public void logSummary(String tag, ConstraintLayoutStatistics prev) {
DecimalFormat df = new DecimalFormat("###.000");
StackTraceElement s = new Throwable().getStackTrace()[1];

Log.v(tag, "CL Perf: -= Performance .(" + s.getFileName() + ":" + s.getLineNumber() + ") =- ");
Log.v(tag, "CL Perf: -= Performance .(" +
s.getFileName() + ":" + s.getLineNumber() + ") =- ");
Log.v(tag, compare(df, prev, DURATION_OF_CHILD_MEASURES));
Log.v(tag, compare(df, prev, DURATION_OF_LAYOUT));
Log.v(tag, compare(df, prev, DURATION_OF_MEASURES));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,4 @@ public void copy(Metrics metrics) {
resolvedWidgets = metrics.resolvedWidgets;
nonresolvedWidgets = metrics.nonresolvedWidgets;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1099,13 +1099,14 @@ private static void parseFlowType(String flowType,
vStyleValueStr = vStyleObject.content();
}

if (vStyleValueStr != "") {
if (!vStyleValueStr.equals("")) {
flow.setVerticalStyle(State.Chain.getValueByString(vStyleValueStr));
}
if (vFirstStyleValueStr != "") {
flow.setFirstVerticalStyle(State.Chain.getValueByString(vFirstStyleValueStr));
if (!vFirstStyleValueStr.equals("")) {
flow.setFirstVerticalStyle(
State.Chain.getValueByString(vFirstStyleValueStr));
}
if (vLastStyleValueStr != "") {
if (!vLastStyleValueStr.equals("")) {
flow.setLastVerticalStyle(State.Chain.getValueByString(vLastStyleValueStr));
}
break;
Expand All @@ -1124,14 +1125,16 @@ private static void parseFlowType(String flowType,
hStyleValueStr = hStyleObject.content();
}

if (hStyleValueStr != "") {
if (!hStyleValueStr.equals("")) {
flow.setHorizontalStyle(State.Chain.getValueByString(hStyleValueStr));
}
if (hFirstStyleValueStr != "") {
flow.setFirstHorizontalStyle(State.Chain.getValueByString(hFirstStyleValueStr));
if (!hFirstStyleValueStr.equals("")) {
flow.setFirstHorizontalStyle(
State.Chain.getValueByString(hFirstStyleValueStr));
}
if (hLastStyleValueStr != "") {
flow.setLastHorizontalStyle(State.Chain.getValueByString(hLastStyleValueStr));
if (!hLastStyleValueStr.equals("")) {
flow.setLastHorizontalStyle(
State.Chain.getValueByString(hLastStyleValueStr));
}
break;
default:
Expand Down Expand Up @@ -1408,7 +1411,6 @@ static void parseWidget(
ConstraintReference reference,
CLObject element
) throws CLParsingException {
float value;
if (reference.getWidth() == null) {
// Default to Wrap when the Dimension has not been assigned
reference.setWidth(Dimension.createWrap());
Expand Down

0 comments on commit b8993a3

Please sign in to comment.