Skip to content

Commit 87d1659

Browse files
committed
兼容安卓,修复异常
1 parent 8e68eeb commit 87d1659

File tree

9 files changed

+135
-36
lines changed

9 files changed

+135
-36
lines changed

android/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ android {
9797
compileSdkVersion 23
9898
buildToolsVersion "23.0.1"
9999

100+
100101
defaultConfig {
101102
applicationId "com.awesomeproject"
102103
minSdkVersion 16
@@ -106,6 +107,8 @@ android {
106107
ndk {
107108
abiFilters "armeabi-v7a", "x86"
108109
}
110+
renderscriptTargetApi 19
111+
renderscriptSupportModeEnabled true
109112
}
110113
splits {
111114
abi {

android/app/src/main/java/com/awesomeproject/MainApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ protected List<ReactPackage> getPackages() {
3535
new MainReactPackage(),
3636
new BlurViewPackage(),
3737
new LinearGradientPackage(),
38-
new CodePush(null, getApplicationContext(), BuildConfig.DEBUG),
39-
new VectorIconsPackage()
38+
new CodePush("FblmCRWTrhBTK4pHOxDzOfdqQvs04ksvOXqog", getApplicationContext(), BuildConfig.DEBUG, "http://180.76.138.89:3000"),
39+
new VectorIconsPackage(),
40+
new ToastReactPackage()
4041
);
4142
}
4243

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.awesomeproject;
2+
3+
import android.widget.Toast;
4+
5+
import com.facebook.react.bridge.NativeModule;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.bridge.ReactContext;
8+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
9+
import com.facebook.react.bridge.ReactMethod;
10+
11+
import java.util.Map;
12+
import java.util.HashMap;
13+
14+
public class ToastModule extends ReactContextBaseJavaModule {
15+
16+
private static final String DURATION_SHORT_KEY = "SHORT";
17+
private static final String DURATION_LONG_KEY = "LONG";
18+
19+
public ToastModule(ReactApplicationContext reactContext) {
20+
super(reactContext);
21+
}
22+
23+
@Override
24+
public String getName() {
25+
return "ToastRoot";//我已经改了
26+
}
27+
28+
@Override
29+
public Map<String, Object> getConstants() {
30+
final Map<String, Object> constants = new HashMap<>();
31+
constants.put(DURATION_SHORT_KEY, Toast.LENGTH_SHORT);
32+
constants.put(DURATION_LONG_KEY, Toast.LENGTH_LONG);
33+
return constants;
34+
}
35+
36+
@ReactMethod
37+
public void show(String message, int duration) {
38+
Toast.makeText(getReactApplicationContext(), message, duration).show();
39+
}
40+
41+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.awesomeproject;
2+
3+
/**
4+
* Created by smallrui on 2018/4/13.
5+
*/
6+
7+
import com.facebook.react.ReactPackage;
8+
import com.facebook.react.bridge.JavaScriptModule;
9+
import com.facebook.react.bridge.NativeModule;
10+
import com.facebook.react.bridge.ReactApplicationContext;
11+
import com.facebook.react.uimanager.ViewManager;
12+
13+
import java.util.ArrayList;
14+
import java.util.Collections;
15+
import java.util.List;
16+
17+
public class ToastReactPackage implements ReactPackage {
18+
19+
//@Override
20+
public List<Class<? extends JavaScriptModule>> createJSModules() {
21+
return Collections.emptyList();
22+
}
23+
24+
@Override
25+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
26+
return Collections.emptyList();
27+
}
28+
29+
@Override
30+
public List<NativeModule> createNativeModules(
31+
ReactApplicationContext reactContext) {
32+
List<NativeModule> modules = new ArrayList<>();
33+
34+
modules.add(new ToastModule(reactContext));
35+
36+
return modules;
37+
}
38+
}

src/components/ModalScreen.js

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React,{ Component } from 'react';
22
import { connect } from 'react-redux';
33
import { ScrollView,View, Text, StatusBar, StyleSheet,findNodeHandle,Image } from 'react-native';
44
import Button from '../modules/Button'
5-
import { BlurView, VibrancyView } from 'react-native-blur';
5+
import { BlurView } from 'react-native-blur';
66
import paragraph from '../equipment/TextParagraph';
77
class ModalScreen extends Component {
88
constructor(props) {
@@ -14,40 +14,41 @@ class ModalScreen extends Component {
1414
}
1515
render() {
1616
return (
17-
1817
<View style={styles.container}>
19-
20-
<StatusBar
21-
backgroundColor={'#EFEFF4'}
22-
animated={true}
23-
barStyle='light-content'
24-
/>
25-
<Image
26-
ref={(img) => { this.backgroundImage = img; }}
27-
source={require("../image/modal_bg.jpg" )}
28-
onLoadEnd={this.imageLoaded.bind(this)}
29-
style={[styles.absolute,{width:'100%',height:'100%'}]}
30-
/>
31-
<BlurView
32-
style={styles.absolute}
33-
blurType="dark"
34-
blurAmount={3}
35-
/>
36-
<ScrollView style={styles.textView} showsVerticalScrollIndicator={false}>
37-
<Text style={styles.paragraphCertent}>
38-
{paragraph}
39-
</Text>
40-
41-
42-
</ScrollView>
43-
<View style={{position:'absolute',bottom:90,right:20,backgroundColor:'rgba(23, 142, 238,.88)',width:50,height:50,borderRadius:25, justifyContent: 'center', alignItems: 'center', }}>
44-
<Button
45-
onClick={() => this.props.navigation.goBack()}
46-
title={"关闭"}
47-
bgColor='rgba(23, 142, 238,0)'
18+
<StatusBar
19+
backgroundColor={'#EFEFF4'}
20+
animated={true}
21+
barStyle='light-content'
22+
/>
23+
<Image
24+
ref={(img) => { this.backgroundImage = img; }}
25+
source={require("../image/modal_bg.jpg" )}
26+
onLoadEnd={this.imageLoaded.bind(this)}
27+
style={[styles.absolute,{width:'100%',height:'100%'}]}
28+
/>
29+
{
30+
this.state.viewRef == null
31+
? null
32+
:<BlurView
33+
style={styles.absolute}
34+
blurType="dark"
35+
blurAmount={3}
36+
viewRef={this.state.viewRef}
4837
/>
38+
}
39+
<ScrollView style={styles.textView} showsVerticalScrollIndicator={false}>
40+
<Text style={styles.paragraphCertent}>
41+
{paragraph}
42+
</Text>
43+
</ScrollView>
44+
<View style={{position:'absolute',bottom:90,right:20,backgroundColor:'rgba(23, 142, 238,.88)',width:50,height:50,borderRadius:25, justifyContent: 'center', alignItems: 'center', }}>
45+
<Button
46+
onClick={() => this.props.navigation.goBack()}
47+
title={"关闭"}
48+
bgColor='rgba(23, 142, 238,0)'
49+
/>
50+
</View>
4951
</View>
50-
</View>
5152

5253
);
5354
}

src/equipment/ComponentUtil.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Platform } from 'react-native';
22

33

44
/* hot push config */
5-
const ANDROID_PRODUCTION = '';
6-
const ANDROID_STAGING = '';
5+
const ANDROID_PRODUCTION = 'FblmCRWTrhBTK4pHOxDzOfdqQvs04ksvOXqog';
6+
const ANDROID_STAGING = 'n7DHTyKwvZBPVpIMmbGgkOS3tnU74ksvOXqog';
77
const IOS_PRODUCTION = 'tKdy8P0D5sGEt1Vf9btpszwMmhzY4ksvOXqog';
88
const IOS_STAGING = 'o1kLkW73Fosz7Wp3MWkWKHNoTbQG4ksvOXqog';
99
const ANDROID_CODEPUS_KEY = __DEV__ ? ANDROID_PRODUCTION : ANDROID_STAGING;

src/modules/Toast.android.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { NativeModules } from 'react-native';
2+
3+
export default NativeModules.ToastRoot;

src/modules/Toast.ios.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { AlertIOS } from 'react-native';
2+
const ToastRoot = {
3+
show:()=>AlertIOS.alert('Plain Text Entry'),
4+
SHORT:"show"
5+
};
6+
export default ToastRoot;

src/page/home/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as dialogType from "../../redux/actions/dialogType";
55
import Button from '../../modules/Button'
66
import { ColorUtils } from "../../equipment/ColorUtils";
77
import * as CONFIG from "../../equipment/ComponentUtil";
8+
import ToastRoot from "../../modules/Toast";
89

910
class HomeScreen extends Component {
1011
static navigationOptions = ({ navigation, navigationOptions }) => {
@@ -80,6 +81,11 @@ class HomeScreen extends Component {
8081
title={"ES6Screen"}
8182
bgColor='#5ACBC8'
8283
/>
84+
<Button
85+
onClick={()=>ToastRoot.show('Toast模块', ToastRoot.SHORT)}
86+
title={"ToastRoot"}
87+
bgColor='#8E44AD'
88+
/>
8389
</View>
8490
</ScrollView>
8591

0 commit comments

Comments
 (0)