Shoutem-修改扩展名 [英] Shoutem - Modifying extensions
问题描述
他,我尝试修改shoutem.places
扩展名.我的自定义屏幕如下所示:
He, I tried to modify the shoutem.places
extension. My custom screen looks like this:
import { screens } from 'shoutem.places';
export default class FixedMediumPlaceDetails extends
screens.MediumPlaceDetails {
render() {
const { place } = this.props;
const { location = {} } = place;
return (
<Screen>
<NavigationBar />
<ScrollView>
{this.renderLeadImage(place)}
</ScrollView>
</Screen>
);
}
}
我只是重写render()
方法,并且在此方法内,我想从超类调用renderLeadImage()
方法.
I am just overriding the render()
method, and inside this method I would like to call the renderLeadImage()
method from the superclass.
通过此实现,我得到:this.renderLeadImage() is not a function
.那么,如何正确继承该类并调用超类的方法呢?无论如何,继承是这里的首选方式吗? Facebook建议在继承中使用组成部分.
With this implementation I get: this.renderLeadImage() is not a function
. So how do I correctly inherit the class and call a superclass' method? Anyhow, is inheritance the preferred way here? Facebook recommends composition over inheritance.
推荐答案
screens.MediumPlaceDetails
不是React Component类,而是redux
和shoutem.theme
装饰的类,这就是为什么要扩展自己的原因无法访问renderLeadImage()
的任何方法.
screens.MediumPlaceDetails
isn't a React Component class, but rather a redux
and shoutem.theme
decorated class, this is why when you're extending you don't have access to any of renderLeadImage()
's methods.
所以您必须更改import
:
import { MediumPlaceDetails } from 'shoutem.places/screens/MediumPlaceDetails';
修复了复制粘贴错误.
Fixed copy-paste error.
这篇关于Shoutem-修改扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!