繁体   English   中英

反应原生无法打开世博项目

[英]react-native can't open expo project

我正在尝试 使用 TabView运行一个世博项目Collapsible Header它在此链接中工作正常。

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

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,
 },
});

我成功了! 我不得不将TabViewAnimated替换为TabView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM