Real API와 React Native CLI를 사용하여 React Native Movies 앱 만들기
16459 단어 reactreactnativemobile
사실 저는 두 프레임워크에서 정확히 같은 애플리케이션을 만들어보고 싶었습니다.
저는 리액트 네이티브로 했고 플러터로 만드는 중입니다.
React Native로 빌드하는 데 소요된 예상 시간은 약 16시간이었습니다.
지금 나는 그것을 설레게 하고 있습니다. 이미 9시간을 보냈고 거의 끝났습니다! (저도 공유할게요)
React Native Documentation 기반으로 설치 및 환경 설정 후
그런 다음 새 프로젝트를 만듭니다.
npx react-native init MoviesApp
모바일 앱에서 화면 간 탐색을 위한 외부 라이브러리인 React Native Navigation 도 사용했습니다.
앱의 구조는 다음과 같습니다.
프로젝트의 진입점은 APP.js입니다. 탐색을 위해 다른 구성 요소를 호출하고 페이지 스택을 추가했습니다.
import React, {useEffect, useState} from 'react';
import {ActivityIndicator, SafeAreaView, StatusBar, Text, View} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import MainNavigator from './src/Navigators/MainNavigator';
import {ThemeColors} from './src/Theme';
import Toast from 'react-native-toast-message';
// API
import {apiKey} from './src/utils';
const colors = ThemeColors.colors;
const App = () => {
const [ready, setReady] = useState(false);
useEffect(() => {
if (apiKey.api_key) {
setReady(true);
}
return () => {
setReady(false);
};
}, []);
return (
<View style={{flex: 1, backgroundColor: colors.background}}>
<StatusBar hidden={true} />
{ready ? (
<NavigationContainer>
<MainNavigator />
</NavigationContainer>
) : (
// Just to check to insert your own Api Key. This would not go to customer
<View>
<ActivityIndicator size={'large'} />
<Text style={{fontSize: 18, color: colors.white}}>
Make sure you inserted your own API Key
</Text>
<Text style={{fontSize: 18, color: colors.white}}>
Located at src/utils/keys
</Text>
</View>
)}
<Toast ref={ref => Toast.setRef(ref)} />
</View>
);
};
export default App;
메인 스택 내비게이션 구성 요소는 화면 구성 요소로 호출합니다.
import React from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import {Home, Detail, Search} from '../Screens';
import {Navbar} from '../Components';
// Theme
import {ThemeColors} from '../Theme';
const colors = ThemeColors.colors;
const Stack = createStackNavigator();
function MainStack() {
return (
<Stack.Navigator
headerMode="screen"
screenOptions={{
headerStyle: {elevation: 0},
cardStyle: {backgroundColor: colors.background},
}}>
<Stack.Screen
name="Home"
component={Home}
options={{
// Add a custom Header to stack navigation
header: ({navigation}) => <Navbar navigation={navigation} />,
headerTransparent: true,
}}
/>
<Stack.Screen
name="Detail"
component={Detail}
options={{
header: ({navigation}) => (
<Navbar main={false} navigation={navigation} />
),
headerTransparent: true,
}}
/>
<Stack.Screen
name="Search"
component={Search}
options={{
header: ({navigation}) => (
<Navbar main={false} navigation={navigation} />
),
headerTransparent: true,
}}
/>
</Stack.Navigator>
);
}
export default function MainNavigator() {
return <MainStack />;
}
많은 세부 사항을 살펴본 후 영화 앱 생성에 대한 전체 설명을 만들었습니다.
Full Course and Explanation about Building React Native Movies App
Reference
이 문제에 관하여(Real API와 React Native CLI를 사용하여 React Native Movies 앱 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/fadinouh1/creating-react-native-movies-app-using-real-api-and-react-native-cli-3ak텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)