Skip to content

Commit c5e2482

Browse files
authored
fix(comp): Warn about using <Image> with children
2 parents f186107 + 13f3e4c commit c5e2482

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

src/index.tsx

+4-17
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ export abstract class BaseCachedImage<P extends CachedImageProps> extends Compon
160160
this.setState({ path });
161161
}
162162

163-
constructor() {
164-
super();
165-
this.state = { path: undefined };
166-
}
167-
168163
private dispose() {
169164
if (this.uri) {
170165
ImageCache.get().dispose(this.uri, this.handler);
@@ -206,6 +201,7 @@ export abstract class BaseCachedImage<P extends CachedImageProps> extends Compon
206201
componentWillMount() {
207202
const {mutable} = this.props;
208203
const source = this.checkSource(this.props.source);
204+
this.state = { path: undefined };
209205
if (source.uri) {
210206
this.observe(source as CachedImageURISource, mutable === true);
211207
}
@@ -226,22 +222,17 @@ export abstract class BaseCachedImage<P extends CachedImageProps> extends Compon
226222

227223
export class CachedImage extends BaseCachedImage<CachedImageProps> {
228224

229-
constructor() {
230-
super();
231-
}
232-
233225
render() {
234226
const props = this.getProps();
227+
if (React.Children.count(this.props.children) > 0) {
228+
console.warn("Using <CachedImage> with children is deprecated, use <CachedImageBackground> instead.");
229+
}
235230
return <Image {...props}>{this.props.children}</Image>;
236231
}
237232
}
238233

239234
export class CachedImageBackground extends BaseCachedImage<CachedImageProps> {
240235

241-
constructor() {
242-
super();
243-
}
244-
245236
render() {
246237
const props = this.getProps();
247238
return <ImageBackground {...props}>{this.props.children}</ImageBackground>;
@@ -250,10 +241,6 @@ export class CachedImageBackground extends BaseCachedImage<CachedImageProps> {
250241

251242
export class CustomCachedImage<P extends CustomCachedImageProps> extends BaseCachedImage<P> {
252243

253-
constructor() {
254-
super();
255-
}
256-
257244
render() {
258245
const {component} = this.props;
259246
const props = this.getProps();

0 commit comments

Comments
 (0)