com.facebook.litho.annotations.OnUpdateState Java Examples
The following examples show how to use
com.facebook.litho.annotations.OnUpdateState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExpandableElementRootComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnUpdateState static void onUpdateList( StateValue<List<Message>> messages, StateValue<Integer> counter, @Param boolean adding, @Param int initialMessagesSize) { final ArrayList<Message> updatedMessageList = new ArrayList<>(messages.get()); int counterValue = counter.get(); if (adding) { updatedMessageList.add( 1, new Message(true, "Just Added #" + counterValue, true, "Recently", true)); counter.set(counterValue + 1); } else if (initialMessagesSize < updatedMessageList.size()) { updatedMessageList.remove(1); } messages.set(updatedMessageList); }
Example #2
Source File: PsiUpdateStateMethodExtractor.java From litho with Apache License 2.0 | 5 votes |
public static ImmutableList<SpecMethodModel<UpdateStateMethod, Void>> getOnUpdateStateMethods( PsiClass psiClass, List<Class<? extends Annotation>> permittedInterStageInputAnnotations, boolean isTransition) { final List<SpecMethodModel<UpdateStateMethod, Void>> delegateMethods = new ArrayList<>(); for (PsiMethod psiMethod : psiClass.getMethods()) { final Annotation onUpdateStateAnnotation = isTransition ? PsiAnnotationProxyUtils.findAnnotationInHierarchy( psiMethod, OnUpdateStateWithTransition.class) : PsiAnnotationProxyUtils.findAnnotationInHierarchy(psiMethod, OnUpdateState.class); if (onUpdateStateAnnotation != null) { final List<MethodParamModel> methodParams = getMethodParams( psiMethod, getPermittedMethodParamAnnotations(permittedInterStageInputAnnotations), permittedInterStageInputAnnotations, ImmutableList.<Class<? extends Annotation>>of()); final SpecMethodModel<UpdateStateMethod, Void> delegateMethod = SpecMethodModel.<UpdateStateMethod, Void>builder() .annotations(ImmutableList.<Annotation>of(onUpdateStateAnnotation)) .modifiers(PsiModifierExtractor.extractModifiers(psiMethod.getModifierList())) .name(psiMethod.getName()) .returnTypeSpec(PsiTypeUtils.generateTypeSpec(psiMethod.getReturnType())) .typeVariables(ImmutableList.<TypeVariableName>of()) .methodParams(copyOf(methodParams)) .representedObject(psiMethod) .build(); delegateMethods.add(delegateMethod); } } return copyOf(delegateMethods); }
Example #3
Source File: SimpleStateUpdateEmulatorSpec.java From litho with Apache License 2.0 | 5 votes |
@OnUpdateState static void onIncrementCount(StateValue<Integer> count) { Integer counter = count.get(); if (counter == null) { throw new RuntimeException("state value is null."); } count.set(counter + 1); }
Example #4
Source File: UpdateStateMethodExtractorTestHelper.java From litho with Apache License 2.0 | 5 votes |
static void assertMethodExtraction( ImmutableList<SpecMethodModel<UpdateStateMethod, Void>> methods) { Assert.assertEquals(1, methods.size()); SpecMethodModel<UpdateStateMethod, Void> updateStateMethod = methods.iterator().next(); List<Annotation> onUpdateStateAnnotations = updateStateMethod.annotations.stream() .filter(x -> x instanceof OnUpdateState) .collect(Collectors.toList()); Assert.assertFalse(onUpdateStateAnnotations.isEmpty()); Assert.assertEquals(1, updateStateMethod.modifiers.size()); Assert.assertTrue(updateStateMethod.modifiers.contains(Modifier.PUBLIC)); Assert.assertEquals("testMethod", updateStateMethod.name.toString()); Assert.assertEquals(TypeName.VOID, updateStateMethod.returnType); Assert.assertEquals(3, updateStateMethod.methodParams.size()); Assert.assertEquals("testProp", updateStateMethod.methodParams.get(0).getName()); Assert.assertEquals(TypeName.BOOLEAN, updateStateMethod.methodParams.get(0).getTypeName()); Assert.assertEquals(1, updateStateMethod.methodParams.get(0).getAnnotations().size()); Assert.assertEquals("testState", updateStateMethod.methodParams.get(1).getName()); Assert.assertEquals(TypeName.INT, updateStateMethod.methodParams.get(1).getTypeName()); Assert.assertEquals(1, updateStateMethod.methodParams.get(1).getAnnotations().size()); Assert.assertEquals("testPermittedAnnotation", updateStateMethod.methodParams.get(2).getName()); Assert.assertEquals( ClassName.bestGuess("java.lang.Object"), updateStateMethod.methodParams.get(2).getTypeName()); Assert.assertEquals(1, updateStateMethod.methodParams.get(2).getAnnotations().size()); }
Example #5
Source File: AnimationStateExampleComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnUpdateState static void updatePosition(StateValue<String> actualPosition, @Param boolean alignStart) { if (alignStart) { actualPosition.set(STATE_START); } else { actualPosition.set(STATE_END); } }
Example #6
Source File: HideableDataDiffSectionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnUpdateState public static void onBlacklistUpdate( StateValue<HashSet> blacklistState, @Param Object modelObject, @Param EventHandler<GetUniqueIdentifierEvent> getUniqueIdentifierHandlerParam) { HashSet<Object> newSet = new HashSet<>(blacklistState.get()); newSet.add( HideableDataDiffSection.dispatchGetUniqueIdentifierEvent( getUniqueIdentifierHandlerParam, modelObject)); blacklistState.set(newSet); }
Example #7
Source File: BlocksSameTransitionKeyComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnUpdateState static void updateState( StateValue<Boolean> state, StateValue<Boolean> running, StateValue<Set<String>> runningAnimations, @Param boolean toggleRunning) { if (toggleRunning && !running.get()) { running.set(true); runningAnimations.get().add(ANIM_ALPHA); runningAnimations.get().add(ANIM_X); state.set(!state.get()); } else if (!toggleRunning) { running.set(false); } }
Example #8
Source File: ToggleMoveBlocksExampleComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnUpdateState static void updateState( StateValue<Integer> state, StateValue<Boolean> running, @Param boolean toggleRunning) { running.set(toggleRunning ? !running.get() : running.get()); if (running.get()) { state.set((state.get() + 1) % 6); } }
Example #9
Source File: ComponentBodyGeneratorTest.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState public void testUpdateStateMethod() {}
Example #10
Source File: StoryCardComponentSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void onToggleSavedState(StateValue<Boolean> saved) { saved.set(!saved.get()); }
Example #11
Source File: ComponentBodyGeneratorTest.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState public void testUpdateStateMethod() {}
Example #12
Source File: UpdateStateMethodExtractor.java From litho with Apache License 2.0 | 4 votes |
private static ImmutableList<SpecMethodModel<UpdateStateMethod, Void>> extractOnUpdateStateMethods( TypeElement typeElement, List<Class<? extends Annotation>> permittedInterStageInputAnnotations, Messager messager, boolean isTransitionMethod) { final List<SpecMethodModel<UpdateStateMethod, Void>> delegateMethods = new ArrayList<>(); for (Element enclosedElement : typeElement.getEnclosedElements()) { if (enclosedElement.getKind() != ElementKind.METHOD) { continue; } final Annotation onUpdateStateAnnotation = isTransitionMethod ? enclosedElement.getAnnotation(OnUpdateStateWithTransition.class) : enclosedElement.getAnnotation(OnUpdateState.class); if (onUpdateStateAnnotation != null) { final ExecutableElement executableElement = (ExecutableElement) enclosedElement; final List<MethodParamModel> methodParams = getMethodParams( executableElement, messager, getPermittedMethodParamAnnotations(permittedInterStageInputAnnotations), permittedInterStageInputAnnotations, ImmutableList.<Class<? extends Annotation>>of()); final SpecMethodModel<UpdateStateMethod, Void> delegateMethod = SpecMethodModel.<UpdateStateMethod, Void>builder() .annotations(ImmutableList.<Annotation>of(onUpdateStateAnnotation)) .modifiers(copyOf(new ArrayList<>(executableElement.getModifiers()))) .name(executableElement.getSimpleName()) .returnTypeSpec(generateTypeSpec(executableElement.getReturnType())) .typeVariables(ImmutableList.of()) .methodParams(copyOf(methodParams)) .representedObject(executableElement) .typeModel(null) .build(); delegateMethods.add(delegateMethod); } } return ImmutableList.copyOf(delegateMethods); }
Example #13
Source File: FullDiffSectionSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState protected static void updateState(StateValue<Object> state1, @Param Object param) {}
Example #14
Source File: FullGroupSectionSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState protected static void updateState(StateValue<Object> state2, @Param Object param) {}
Example #15
Source File: TestLayoutSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void updateCurrentState(StateValue<Long> state1, @Param int someParam) {}
Example #16
Source File: TestMountSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void updateCurrentState(StateValue<Long> state1, @Param int someParam) {}
Example #17
Source File: LearningStateComponentSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void incrementClickCount(StateValue<Integer> count) { count.set(count.get() + 1); }
Example #18
Source File: FavouriteButtonSpec.java From litho-glide with MIT License | 4 votes |
@OnUpdateState static void toggleFavourited(StateValue<Boolean> favourited) { favourited.set(!favourited.get()); }
Example #19
Source File: VerySimpleGroupSectionSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void onUpdateState(StateValue<Integer> extra, @Param int newExtra) { extra.set(newExtra); }
Example #20
Source File: StateContainerGeneratorTest.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static <T, E, D> void updateValues( StateValue<Function<E, D>> functions, @Param Function<T, D> foos) {}
Example #21
Source File: StateContainerGeneratorTest.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static <T> void updateValues(StateValue<List<T>> values, @Param List<T> foos) {}
Example #22
Source File: StateContainerGeneratorTest.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState void testUpdateState() {}
Example #23
Source File: StateContainerGeneratorTest.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState void testUpdateState() {}
Example #24
Source File: BuilderGeneratorTest.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState public void testUpdateStateMethod() {}
Example #25
Source File: TestErrorBoundarySpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void updateError(StateValue<Optional<String>> error, @Param String errorMsg) { error.set(Optional.of(errorMsg)); }
Example #26
Source File: LayoutSpecLifecycleTesterSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void updateState(@Param List<LifecycleStep.StepInfo> stepsAsParam) { stepsAsParam.add(new StepInfo(LifecycleStep.ON_UPDATE_STATE)); }
Example #27
Source File: ChildComponentWithStateUpdateSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState public static void onUpdateState(StateValue<Integer> count) { count.set(count.get() + 1); }
Example #28
Source File: TransitionEndCallbackTestComponentSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void updateState(StateValue<Boolean> state) { state.set(!state.get()); }
Example #29
Source File: TestAnimationsComponentSpec.java From litho with Apache License 2.0 | 4 votes |
@OnUpdateState static void updateState(StateValue<Boolean> state) { state.set(!state.get()); }
Example #30
Source File: FavouriteButtonSpec.java From litho-picasso with MIT License | 4 votes |
@OnUpdateState static void toggleFavourited(StateValue<Boolean> favourited) { favourited.set(!favourited.get()); }