فهرست منبع

1.添加全局loading
2.添加android需要gif图支持

zhangmengjie 5 سال پیش
والد
کامیت
8c1fa4ab8c

+ 1 - 0
App.js

@@ -24,6 +24,7 @@ import Login from './pages/Login';
 import SearchResult from './pages/searchResult';
 import PhoneBind from './pages/PhoneBind';
 import Splash from './pages/Splash';
+import './pages/components/RootView';
 
 const RootNavigator = createStackNavigator(
 	{

+ 2 - 0
android/app/build.gradle

@@ -161,6 +161,8 @@ dependencies {
     implementation project(':react-native-gesture-handler')
     implementation project(':react-native-image-picker')
     implementation fileTree(dir: "libs", include: ["*.jar"])
+    // 如果你需要支持GIF动图
+    implementation 'com.facebook.fresco:animated-gif:1.10.0'
     implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
     implementation "com.facebook.react:react-native:+"  // From node_modules
 

+ 0 - 24
android/app/src/main/java/com/edufound/mobile/view/modal/BUCK

@@ -1,24 +0,0 @@
-load("//tools/build_defs/oss:rn_defs.bzl", "YOGA_TARGET", "react_native_dep", "react_native_target", "rn_android_library")
-
-rn_android_library(
-    name = "modal",
-    srcs = glob(["*.java"]),
-    required_for_source_only_abi = True,
-    visibility = [
-        "PUBLIC",
-    ],
-    deps = [
-        YOGA_TARGET,
-        react_native_dep("third-party/java/infer-annotations:infer-annotations"),
-        react_native_dep("third-party/java/jsr-305:jsr-305"),
-        react_native_target("java/com/facebook/react/bridge:bridge"),
-        react_native_target("java/com/facebook/react/common:common"),
-        react_native_target("java/com/facebook/react/module/annotations:annotations"),
-        react_native_target("java/com/facebook/react/touch:touch"),
-        react_native_target("java/com/facebook/react/uimanager:uimanager"),
-        react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
-        react_native_target("java/com/facebook/react/views/common:common"),
-        react_native_target("java/com/facebook/react/views/view:view"),
-        react_native_target("res:modal"),
-    ],
-)

BIN
android/app/src/main/res/drawable-mdpi/pages_images_common_loading.gif


+ 58 - 0
pages/components/Loading.js

@@ -0,0 +1,58 @@
+import React, { Component } from 'react';
+import { StyleSheet, Text, View, ActivityIndicator, Dimensions, Image } from 'react-native';
+const { width, height } = Dimensions.get('window');
+_this = null;
+class Loading extends Component {
+	constructor(props) {
+		super(props);
+		_this = this;
+		this.state = {
+			show: false
+		};
+	}
+	static show = () => {
+		_this.setState({ show: true });
+	};
+	static hide = () => {
+		_this.setState({ show: false });
+	};
+	render() {
+		if (this.state.show) {
+			return (
+				<View style={styles.LoadingPage}>
+					{/* <View
+						style={{
+							width: 100,
+							height: 100,
+							backgroundColor: 'rgba(0,0,0,0.6)',
+							opacity: 1,
+							justifyContent: 'center',
+							alignItems: 'center',
+							borderRadius: 7
+						}}
+					>
+						<ActivityIndicator size="large" color="#FFF" />
+						<Text style={{ marginLeft: 10, color: '#FFF', marginTop: 10 }}>正在加载...</Text> */}
+					{/* </View> */}
+
+					<Image source={require('../images/common/loading.gif')} />
+				</View>
+			);
+		} else {
+			return <View />;
+		}
+	}
+}
+export default Loading;
+const styles = StyleSheet.create({
+	LoadingPage: {
+		position: 'absolute',
+		left: 0,
+		top: 0,
+		backgroundColor: 'rgba(0,0,0,0)',
+		width: width,
+		height: height,
+		justifyContent: 'center',
+		alignItems: 'center'
+	}
+});

+ 9 - 5
pages/components/MainPage.js

@@ -96,7 +96,8 @@ export default class MainPage extends BasePage {
 		scheduleWeek: '1',
 		username: '游客',
 		avatar: '',
-		isVip: false
+		isVip: false,
+		showLoading: true
 	};
 
 	renderBtn = (item, index) => {
@@ -194,8 +195,11 @@ export default class MainPage extends BasePage {
 				{/* 搜索区域 */}
 				<View style={styles.searchSection}>
 					<View style={styles.searchBox}>
-						<TouchableOpacity onPress={() => this.search(this)} style={{position: 'absolute', left: '45%', top: 10}}>
-							<Image style={styles.search} source={require('../images/common/search.png')}></Image>
+						<TouchableOpacity
+							onPress={() => this.search(this)}
+							style={{ position: 'absolute', left: '45%', top: 10 }}
+						>
+							<Image style={styles.search} source={require('../images/common/search.png')} />
 						</TouchableOpacity>
 					</View>
 					<TouchableOpacity onPress={this.tabCallOutHandler}>
@@ -521,7 +525,7 @@ export default class MainPage extends BasePage {
 	}
 	// 搜索
 	search() {
-		this.toNextPage('SearchResult')
+		this.toNextPage('SearchResult');
 	}
 }
 
@@ -555,7 +559,7 @@ const styles = StyleSheet.create({
 	},
 	search: {
 		width: 30,
-		height: 30,
+		height: 30
 	},
 	rightBtn: {
 		width: Dimensions.getWidth(113),

+ 32 - 0
pages/components/RootView.js

@@ -0,0 +1,32 @@
+import React, { Component } from 'react';
+import { StyleSheet, AppRegistry, View, Text } from 'react-native';
+import Loading from './Loading';
+// import Toast from './Toast';
+// import Popup from './Popup';
+const originRegister = AppRegistry.registerComponent;
+AppRegistry.registerComponent = (appKey, component) => {
+	return originRegister(appKey, function() {
+		const OriginAppComponent = component();
+		return class extends Component {
+			render() {
+				return (
+					<View style={styles.container}>
+						<OriginAppComponent />
+						{/* 弹窗
+						<Popup /> */}
+						{/* 提示 */}
+						{/* <Toast /> */}
+						{/* //加载动画 */}
+						<Loading />
+					</View>
+				);
+			}
+		};
+	});
+};
+const styles = StyleSheet.create({
+	container: {
+		flex: 1,
+		position: 'relative'
+	}
+});

+ 7 - 1
pages/services/user.js

@@ -1,7 +1,7 @@
 import APIConfig from './api.js';
 import efunRequest from '../utils/efunRequest';
 import request from '../utils/request';
-
+import Loading from '../components/Loading';
 export default class user {
 	// 个人中心
 	static userMember() {
@@ -20,6 +20,7 @@ export default class user {
 	* @return 返回Promise 
 	*/
 	static async uploadImage(photo_url) {
+		Loading.show();
 		const file_uid = await getuid();
 		let formData = new FormData();
 		formData.append('file', {
@@ -35,13 +36,16 @@ export default class user {
 			.then((response) => {
 				console.log('res1', response);
 				if (response.status >= 200 && response.status < 300) {
+					Loading.hide();
 					return response;
 				}
 				const error = new Error(response.statusText);
 				error.response = response;
+				Loading.hide();
 				throw error;
 			})
 			.then((response) => {
+				Loading.hide();
 				return response.json();
 			})
 			.then((data) => {
@@ -49,10 +53,12 @@ export default class user {
 				if (!data.success) {
 					const code = data;
 				}
+				Loading.hide();
 				return data;
 			})
 			.catch((err) => {
 				console.log('err', err);
+				Loading.hide();
 				return {
 					err
 				};

+ 5 - 0
pages/utils/request.js

@@ -1,3 +1,4 @@
+import Loading from '../components/Loading';
 /**
  * 检查HTTP请求状态
  */
@@ -15,6 +16,7 @@ function checkStatus(response) {
  * 将Response内容转为JSON格式
  */
 function parseJSON(response) {
+	Loading.hide();
 	return response.json();
 }
 
@@ -26,6 +28,7 @@ function checkAPIDatas(data) {
 	if (!data.success) {
 		const code = data;
 	}
+	Loading.hide();
 	return data;
 }
 
@@ -35,6 +38,7 @@ function checkAPIError(err) {
 	// const status = err.response.status;
 	// const { url, type, oStatus, statusText } = err.response;
 	// Message.error(`地址:${url} 类型:${type} 状态:${oStatus} 信息:${statusText}`, 10);
+	Loading.hide();
 	return {
 		err
 	};
@@ -48,6 +52,7 @@ function checkAPIError(err) {
  */
 
 const request = async (url, options) => {
+	Loading.show();
 	const file_uid = await getuid();
 
 	if (options) {