MCPcopy Create free account
hub / github.com/Snapchat/Valdi / App

Class App

apps/managed_context_example/ManagedContextExample.tsx:72–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72export class App extends StatefulComponent<{}, State> {
73 state: State = {
74 rasterMethod: EmbeddedPlatformViewRasterMethod.FAST,
75 downscaleRatioIndex: 0,
76 };
77
78 onRender(): void {
79 <view width={'100%'} height={'100%'} paddingTop={Device.getDisplayTopInset()} backgroundColor="white">
80 <Section name="Preview">
81 {
82 <layout height={COMPONENT_HEIGHT}>
83 <InnerComponent />
84 </layout>
85 }
86 </Section>
87 <Section name="Rasterized">
88 {<image src={this.state.rasterizedAsset} width={'100%'} height={COMPONENT_HEIGHT} />}
89 </Section>
90 <Section name="Controls">
91 <layout flexDirection="column" padding={8}>
92 <Button
93 title={`Raster method: ${
94 this.state.rasterMethod === EmbeddedPlatformViewRasterMethod.FAST ? 'Fast' : 'Accurate'
95 }`}
96 onTap={this.toggleRasterMethod}
97 />
98 <Button
99 title={`Downscale ratio: ${DOWNSCALE_RATIO[this.state.downscaleRatioIndex]}`}
100 onTap={this.toggleDownscaleRatio}
101 />
102 <Button title="Rasterize" onTap={this.rasterize} />
103 </layout>
104 </Section>
105 </view>;
106 }
107
108 toggleDownscaleRatio = () => {
109 const nextDownscaleRatioIndex = (this.state.downscaleRatioIndex + 1) % DOWNSCALE_RATIO.length;
110 this.setState({
111 downscaleRatioIndex: nextDownscaleRatioIndex,
112 });
113 };
114
115 toggleRasterMethod = () => {
116 this.setState({
117 rasterMethod:
118 this.state.rasterMethod === EmbeddedPlatformViewRasterMethod.FAST
119 ? EmbeddedPlatformViewRasterMethod.ACCURATE
120 : EmbeddedPlatformViewRasterMethod.FAST,
121 });
122 };
123
124 rasterize = () => {
125 this.doRasterize()
126 .then(asset => {
127 console.log('Rasterized asset:', asset);
128 this.setState({ rasterizedAsset: asset });
129 })

Callers

nothing calls this directly

Calls 5

doRasterizeMethod · 0.95
thenMethod · 0.65
logMethod · 0.65
errorMethod · 0.65
setStateMethod · 0.45

Tested by

no test coverage detected