Browse Source

Merge branch 'master' of http://gogs.efunbox.cn/Rorschach/efunbox-mobile-8

Limengbo 5 years ago
parent
commit
3390702536

+ 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'
+	}
+});

+ 10 - 5
pages/components/MainPage.js

@@ -30,6 +30,7 @@ import LibraryUrl from '../services/library';
 import { ScrollView } from 'react-native-gesture-handler';
 import commonutil from '../utils/commonutil';
 import http_user from '../services/user';
+import Toast from '../components/Toast';
 
 export default class MainPage extends BasePage {
 	constructor(props) {
@@ -96,7 +97,8 @@ export default class MainPage extends BasePage {
 		scheduleWeek: '1',
 		username: '游客',
 		avatar: '',
-		isVip: false
+		isVip: false,
+		showLoading: true
 	};
 
 	renderBtn = (item, index) => {
@@ -194,8 +196,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 +526,7 @@ export default class MainPage extends BasePage {
 	}
 	// 搜索
 	search() {
-		this.toNextPage('SearchResult')
+		this.toNextPage('SearchResult');
 	}
 }
 
@@ -555,7 +560,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'
+	}
+});

+ 134 - 0
pages/components/Toast.js

@@ -0,0 +1,134 @@
+import React, { Component } from 'react';
+
+import { StyleSheet, View, Easing, Dimensions, Text, Animated } from 'react-native';
+import ModalView from '../utils/ModalUtil';
+const { width, height } = Dimensions.get('window');
+class AddToast extends Component {
+	constructor(props) {
+		super(props);
+		this.state = {
+			fadeAnim: new Animated.Value(0)
+		};
+	}
+	componentDidMount() {
+		this.anim = Animated.sequence([
+			// 使用宽松函数让数值随时间动起来。
+			Animated.timing(
+				// 随时间变化而执行动画
+				this.state.fadeAnim, // 动画中的变量值
+				{
+					toValue: 1, // 透明度最终变为1,即完全不透明
+					duration: 500 // 让动画持续一段时间
+				}
+			)
+			// Animated.delay(4000),
+		]).start();
+		this.anim_timeout = setTimeout(() => {
+			this.props.delete();
+		}, 3000);
+	}
+	componentWillUnmount() {
+		clearTimeout(this.anim_timeout);
+	}
+
+	render() {
+		let { fadeAnim } = this.state;
+		const opacity = fadeAnim.interpolate({
+			inputRange: [ 0, 1 ],
+			outputRange: [ 0, 1 ]
+		});
+		const translateY = fadeAnim.interpolate({
+			inputRange: [ 0, 1 ],
+			outputRange: [ 20, 0 ]
+		});
+		return (
+			<Animated.Text // 使用专门的可动画化的Text组件
+				style={{
+					opacity: opacity, // 将透明度指定为动画变量值
+					backgroundColor: 'white',
+					borderRadius: 10,
+					color: 'black',
+					marginTop: 5,
+					width: '70%',
+					textAlign: 'center',
+					textAlignVertical: 'center',
+					height: '15%',
+					fontSize: 22,
+					transform: [ { translateY: translateY } ]
+				}}
+			>
+				{this.props.children}
+			</Animated.Text>
+		);
+	}
+}
+let _this;
+let key = 0;
+class ToastView extends Component {
+	constructor(props) {
+		super(props);
+		_this = this;
+		this.state = {
+			toastList: [],
+			modalVisible: false
+		};
+		this.deleteToast = this.deleteToast.bind(this);
+	}
+	static add = (value) => {
+		var toastList = _this.state.toastList;
+		var toastAddState = true;
+		toastList.forEach((item, index) => {
+			if (item.text === value) {
+				toastAddState = false;
+			}
+		});
+		if (toastAddState) {
+			toastList.push({
+				text: value,
+				value: (
+					<AddToast key={key} delete={_this.deleteToast} visible={_this.state.modalVisible}>
+						{value}
+					</AddToast>
+				)
+			});
+			key++;
+			_this.setState({ toastList: toastList, modalVisible: true });
+		}
+	};
+	deleteToast() {
+		var toastList = this.state.toastList;
+		toastList.splice(0, 1);
+		this.setState({ toastList: toastList, modalVisible: false });
+	}
+
+	getView = () => {
+		return (
+			<View
+				style={{
+					position: 'absolute',
+					height: '100%',
+					width: '100%',
+					justifyContent: 'center',
+					alignItems: 'center'
+				}}
+			>
+				{this.state.toastList.map((item, index) => {
+					return item.value;
+				})}
+			</View>
+		);
+	};
+	render() {
+		return (
+			<ModalView
+				close={() => {
+					this.setState(this.deleteToast());
+				}}
+				visible={this.state.modalVisible}
+				customerlayout={{ flex: 1, justifyContent: 'flex-end' }}
+				contentView={this.getView}
+			/>
+		);
+	}
+}
+export default ToastView;

BIN
pages/images/common/loading.gif


+ 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
 				};

+ 0 - 1
pages/utils/ModalUtil.js

@@ -59,7 +59,6 @@ export default class ModalView extends Component {
 			}
 		});
 	};
-
 	renderContent = () => this.props.contentView();
 
 	render() {

+ 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) {