react-native无法打开EXPO项目

奶油

我正在尝试使用TabView运行博览会项目可折叠标头,在此链接中可以正常工作。

但是,当我将代码复制并粘贴到我自己的expo项目中时,它给了我一个错误。

Invariant Violation: Element type is invalid: expected a string or a class/function. Check the render method of App

我唯一更改的是class TabViewclass App但是它给了我这个错误。

另外,如果我要构建本机代码项目而不是expo。我将如何运行此代码?因为有import {Constants } from expo这是行不通的react-native run-ios

import * as React from 'react';
import {
  View,
  StyleSheet,
  Dimensions,
  ImageBackground,
  Animated,
  Text
} from 'react-native';
import { Constants } from 'expo';
import { TabViewAnimated, TabBar } from 'react-native-tab-view'; // Version can be specified in package.json
import ContactsList from './components/ContactsList';

const initialLayout = {
  height: 0,
  width: Dimensions.get('window').width,
};

const HEADER_HEIGHT = 240;
const COLLAPSED_HEIGHT = 52 + Constants.statusBarHeight;
const SCROLLABLE_HEIGHT = HEADER_HEIGHT - COLLAPSED_HEIGHT;

export default class TabView extends React.Component {
  constructor(props: Props) {
     super(props);

     this.state = {
       index: 0,
       routes: [
         { key: '1', title: 'First' },
         { key: '2', title: 'Second' },
         { key: '3', title: 'Third' },
       ],
       scroll: new Animated.Value(0),
     };
   }

   _handleIndexChange = index => {
     this.setState({ index });
   };

   _renderHeader = props => {
     const translateY = this.state.scroll.interpolate({
       inputRange: [0, SCROLLABLE_HEIGHT],
       outputRange: [0, -SCROLLABLE_HEIGHT],
       extrapolate: 'clamp',
     });

     return (
       <Animated.View style={[styles.header, { transform: [{ translateY }] }]}>
         <ImageBackground
           source={{ uri: 'https://picsum.photos/900' }}
           style={styles.cover}>
           <View style={styles.overlay} />
           <TabBar {...props} style={styles.tabbar} />
         </ImageBackground>
       </Animated.View>
     );
   };

   _renderScene = () => {
     return (
       <ContactsList
         scrollEventThrottle={1}
         onScroll={Animated.event(
           [{ nativeEvent: { contentOffset: { y: this.state.scroll } } }],
           { useNativeDriver: true }
         )}
         contentContainerStyle={{ paddingTop: HEADER_HEIGHT }}
       />
     );
   };

  render() {
    return (
     <TabViewAnimated
       style={styles.container}
       navigationState={this.state}
       renderScene={this._renderScene}
       renderHeader={this._renderHeader}
       onIndexChange={this._handleIndexChange}
       initialLayout={initialLayout}
     />
   );
 }
}

const styles = StyleSheet.create({
 container: {
   flex: 1,
 },
 overlay: {
   flex: 1,
   backgroundColor: 'rgba(0, 0, 0, .32)',
 },
 cover: {
   height: HEADER_HEIGHT,
 },
 header: {
   position: 'absolute',
   top: 0,
   left: 0,
   right: 0,
   zIndex: 1,
 },
 tabbar: {
   backgroundColor: 'rgba(0, 0, 0, .32)',
   elevation: 0,
   shadowOpacity: 0,
 },
});
奶油

我知道了!我不得不替换TabViewAnimatedTabView

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章