@Override public void putHierarchy(LayoutHierarchyDumper dumper, JSONObject root, Object obj, Point offset) throws JSONException { if (!accept(obj)) { return; } if (obj instanceof LithoView) { LithoView lithoView = (LithoView) obj; DebugComponent debugComponent = DebugComponent.getRootInstance(lithoView); if (debugComponent == null) { return; } final int offsetLeft = LayoutHierarchyDumper.getViewLeft(lithoView); final int offsetTop = LayoutHierarchyDumper.getViewTop(lithoView); offset.offset(offsetLeft, offsetTop); dumpHierarchy(dumper, root, debugComponent, offset); offset.offset(-offsetLeft, -offsetTop); } else { dumpHierarchy(dumper, root, (DebugComponent) obj, offset); } }
@Override public void putAttributes(JSONObject node, Object obj, Point offset) throws JSONException { final DebugComponent debugComponent; if (obj instanceof LithoView) { ((LithoView) obj).rebind(); debugComponent = DebugComponent.getRootInstance((LithoView) obj); if (debugComponent == null) { return; } } else { debugComponent = (DebugComponent) obj; // Since we're dealing with a pure component, we cant rely on the default required // attributes to be added, so we add them here Rect bounds = debugComponent.getBoundsInLithoView(); putRequired( node, debugComponent.getComponent().getClass().getName(), offset.x + bounds.left, offset.y + bounds.top, bounds.width(), bounds.height()); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Demos.initialize(this); final String demoName = (String) getIntent().getSerializableExtra("demoName"); setContentView( LithoView.create( this, Demos.getComponent(demoName))); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Demos.initialize(this); setContentView( LithoView.create( this, DemoListComponent.create(new ComponentContext(this)) .build())); }
@Override public void initData() { final ComponentContext c = new ComponentContext(this); final LithoView lithoView = LithoView.create( this /* context */, Text.create(c) .text("Hello, World!") .textSizeDip(50) .build()); setContentView(lithoView); }
@Test public void testDefault() { Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); LayoutInflater inflater = LayoutInflater.from(targetContext); LithoView view = (LithoView) inflater.inflate(R.layout.litho_view, null, false); view.setComponent(Example.create(view.getComponentContext()).build()); ViewHelpers.setupView(view).setExactWidthDp(300).layout(); Screenshot.snap(view).record(); }
@Test public void testDefault() { Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); LayoutInflater inflater = LayoutInflater.from(targetContext); LithoView view = (LithoView) inflater.inflate(R.layout.litho_view, null, false); view.setComponent(ImageRow.create(view.getComponentContext()).build()); ViewHelpers.setupView(view).setExactWidthDp(300).layout(); Screenshot.snap(view).record(); }
@Override public boolean accept(Object obj) { return obj instanceof LithoView || obj instanceof DebugComponent; }
@Test public void testAcceptsLithoView() throws Exception { LithoView lithoView = new LithoView(InstrumentationRegistry.getTargetContext()); assertEquals(true, LithoHierarchyPlugin.getInstance().accept(lithoView)); }
@Test public void testAcceptsLithoView() throws Exception { LithoView lithoView = new LithoView(InstrumentationRegistry.getTargetContext()); assertEquals(true, LithoAttributePlugin.getInstance().accept(lithoView)); }