Summary: This diff adds support for `com.facebook.litho.sections.Section` which mimics the behavior for `com.facebook.litho.Component`. Reviewed By: skcho Differential Revision: D22309039 fbshipit-source-id: 3510441a8master
parent
bfe2caf92d
commit
83a83ce9e0
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
package codetoanalyze.java.litho;
|
||||||
|
|
||||||
|
import com.facebook.litho.annotations.Prop;
|
||||||
|
import com.facebook.litho.sections.Section;
|
||||||
|
|
||||||
|
public class MySection extends Section {
|
||||||
|
@Prop Object prop1; // implicitly non-optional
|
||||||
|
|
||||||
|
@Prop(optional = true)
|
||||||
|
Object prop2; // explicitly optional
|
||||||
|
|
||||||
|
public Builder create() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends Section.Builder<Builder> {
|
||||||
|
MySection mMySection;
|
||||||
|
|
||||||
|
public Builder prop1(Object o) {
|
||||||
|
this.mMySection.prop1 = o;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder prop2(Object o) {
|
||||||
|
this.mMySection.prop2 = o;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MySection build() {
|
||||||
|
return mMySection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package codetoanalyze.java.litho;
|
||||||
|
|
||||||
|
import com.facebook.litho.sections.Section;
|
||||||
|
|
||||||
|
public class RequiredPropsSection {
|
||||||
|
|
||||||
|
public MySection mMySection;
|
||||||
|
|
||||||
|
public Section buildWithAllOk() {
|
||||||
|
return mMySection.create().prop1(new Object()).prop2(new Object()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// prop 2 is optional
|
||||||
|
public Section buildWithout2Ok() {
|
||||||
|
return mMySection.create().prop1(new Object()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// prop 1 is required
|
||||||
|
public Section buildWithout1Bad() {
|
||||||
|
return mMySection.create().prop2(new Object()).build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.litho.sections;
|
||||||
|
|
||||||
|
public class Section {
|
||||||
|
|
||||||
|
public abstract static class Builder<T extends Builder<T>> {
|
||||||
|
|
||||||
|
public abstract Section build();
|
||||||
|
|
||||||
|
public abstract T getThis();
|
||||||
|
|
||||||
|
public T commonProp(Object prop) {
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue