Skip to content

Commit

Permalink
Add OnLayoutCalculated component lifecycle method
Browse files Browse the repository at this point in the history
  • Loading branch information
tjaneczko committed Apr 23, 2021
1 parent d2b3dd0 commit 316383d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.facebook.litho.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface OnLayoutCalculated {}
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ protected void onBind(ComponentContext c, Object mountedContent) {
*/
protected void onBoundsDefined(ComponentContext c, ComponentLayout layout) {}

/**
* Called after the layout calculation is finished.
*
* @param c The {@link Context} used by this component.
*/
protected void onLayoutCalculated(ComponentContext c) {}

/**
* Generate a tree of {@link ComponentLayout} representing the layout structure of the {@link
* Component} and its sub-components.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ && isLayoutDirectionRTL(c.getAndroidContext())) {

mYogaNode.calculateLayout(width, height);

for (Component component : mComponents) {
component.onLayoutCalculated(mComponentContext);
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.facebook.litho.annotations.OnCreateMountContentPool;
import com.facebook.litho.annotations.OnCreateTransition;
import com.facebook.litho.annotations.OnDetached;
import com.facebook.litho.annotations.OnLayoutCalculated;
import com.facebook.litho.annotations.OnError;
import com.facebook.litho.annotations.OnLoadStyle;
import com.facebook.litho.annotations.OnMeasure;
Expand Down Expand Up @@ -162,6 +163,18 @@ public final class DelegateMethodDescriptions {
.build()))
.build();

public static final DelegateMethodDescription ON_LAYOUT_CALCULATED =
DelegateMethodDescription.newBuilder()
.annotations(ImmutableList.of(AnnotationSpec.builder(Override.class).build()))
.accessType(Modifier.PROTECTED)
.returnType(TypeName.VOID)
.name("onLayoutCalculated")
.definedParameterTypes(
ImmutableList.<TypeName>of(ClassNames.COMPONENT_CONTEXT))
.optionalParameterTypes(
ImmutableList.of(PROP, TREE_PROP, STATE, INJECT_PROP, CACHED_VALUE))
.build();

public static final DelegateMethodDescription ON_CREATE_INITIAL_STATE =
DelegateMethodDescription.newBuilder()
.annotations(ImmutableList.of(AnnotationSpec.builder(Override.class).build()))
Expand Down Expand Up @@ -521,6 +534,7 @@ public int compare(Class<? extends Annotation> lhs, Class<? extends Annotation>
layoutSpecDelegateMethodsMap.put(ShouldUpdate.class, SHOULD_UPDATE);
layoutSpecDelegateMethodsMap.put(OnAttached.class, ON_ATTACHED);
layoutSpecDelegateMethodsMap.put(OnDetached.class, ON_DETACHED);
layoutSpecDelegateMethodsMap.put(OnLayoutCalculated.class, ON_LAYOUT_CALCULATED);
LAYOUT_SPEC_DELEGATE_METHODS_MAP = Collections.unmodifiableMap(layoutSpecDelegateMethodsMap);

Map<Class<? extends Annotation>, DelegateMethodDescription> mountSpecDelegateMethodsMap =
Expand Down

0 comments on commit 316383d

Please sign in to comment.