报错内容如下:
Exception thrown while executing UI block: *** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]
__44-[RCTUIManager flushUIBlocksWithCompletion:]_block_invoke
RCTUIManager.m:1183
__44-[RCTUIManager flushUIBlocksWithCompletion:]_block_invoke.489
__RCTExecuteOnMainQueue_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_callback_4CF
CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
UIApplicationMain
main
start
0x0
用官方的那个就不会报这个错
代码如下:
const connector = connect(({ home }: rootState) => {
return {
...home,
colors:
home.banners && home.banners.length > 0
? home.banners[home.activeCarouselIndex].colors
: undefined,
};
});
//首页顶部标题栏组件
type modelState = ConnectedProps;
type IProps = MaterialTopTabBarProps & modelState;
class index extends Component {
get linearGradient() {
const { colors = [] } = this.props;
console.log(colors, "sss");
return <LinearGradient colors={colors} style={styles.gradient} />;
}
render() {
const { props } = this;
return (
{this.linearGradient}
<MaterialTopTabBar style={styles.tabBar} {...props} />
分类
搜索关键词
历史记录
);
}
}
export default connector(index);
const styles = StyleSheet.create({
container: {
paddingTop: getStatusBarHeight(),
backgroundColor: "#fff",
},
tabBar: {
elevation: 0, //清除安卓标题栏的投影
flex: 1,
overflow: "hidden", //ios 不加此属性 会出现溢出的边框
backgroundColor: "transparent",
},
tabBarTop: {
flexDirection: "row",
alignItems: "center",
},
categoryBtn: {
paddingHorizontal: 10,
borderLeftColor: "#ccc",
borderLeftWidth: StyleSheet.hairlineWidth,
},
tabBarBottom: {
flexDirection: "row",
alignItems: "center",
paddingHorizontal: 15,
paddingVertical: 7,
},
searchBtn: {
flex: 1,
paddingVertical: 10,
backgroundColor: "rgba(0,0,0,0.1)",
borderRadius: 15,
paddingLeft: 15,
},
historyBtn: {
marginLeft: 24,
},
gradient: {
height: 260,
...StyleSheet.absoluteFillObject,
},
});