@@ -28,3 +28,141 @@ callback(err,action,button) : 回调
28
28
* err : 当options为null时返回
29
29
* action : 返回"buttonClicked"
30
30
* button : 返回"positive" || "negative"
31
+
32
+ ## 安装及使用
33
+
34
+ #### 第一步 : 安装npm包
35
+
36
+ ``` shell
37
+ npm install --save react-native-popupwindow
38
+ ```
39
+
40
+ #### 第二步 : 更新settings.gradle
41
+
42
+ ``` gradle
43
+ // 文件路径:android/settings.gradle
44
+
45
+ ...
46
+
47
+ include ':reactpopupwindow', ':app'
48
+ project(':reactpopupwindow').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-popupwindow')
49
+
50
+ // 如果有其他的library,这样添加:
51
+
52
+ // include ':app' , ':libraryone' , ':librarytwo' , 'more...'
53
+ // project(':libraryonename').projectDir = new File(rootProject.projectDir, '../node_modules/libraryonemodule')
54
+ // project(':librarytwoname').projectDir = new File(rootProject.projectDir, '../node_modules/librarytwomodule')
55
+ // more..
56
+ ```
57
+
58
+ #### 第三步 : 更新app的build.gradle
59
+
60
+ ``` gradle
61
+ // 文件路径:android/app/build.gradle
62
+ // file: android/app/build.gradle
63
+ ...
64
+
65
+ dependencies {
66
+ ...
67
+ compile project(':reactpopupwindow')
68
+ }
69
+ ```
70
+
71
+ #### 第四步 : 注册包
72
+
73
+ ``` java
74
+ ...
75
+ import com.bee.popupwindow.PopupWindowPackage ; // 导入类
76
+
77
+ public class MainActivity extends ReactActivity {
78
+
79
+ ...
80
+
81
+ @Override
82
+ protected List<ReactPackage > getPackages () {
83
+ return Arrays . < ReactPackage > asList(
84
+ new MainReactPackage (),
85
+ new PopupWindowPackage (MainActivity . this )
86
+ );
87
+ }
88
+
89
+ ```
90
+
91
+ #### 第五步 : 在你的JS 文件中使用
92
+ ```javascript
93
+ ' use strict' ;
94
+ import React , {
95
+ AppRegistry ,
96
+ Component ,
97
+ StyleSheet ,
98
+ Text ,
99
+ View ,
100
+ ToastAndroid ,
101
+ } from ' react-native' ;
102
+
103
+ import MyPop from ' react-native-popupwindow' ;
104
+ let options = {
105
+ title: ' 提示' ,
106
+ message: ' 确认退出么?' ,
107
+ positive: ' 确定' ,
108
+ negative: ' 取消' ,
109
+ };
110
+
111
+ class PopupWindow extends Component {
112
+ right (){
113
+ MyPop . showPopupWindow(options,(err,action,button) = > {
114
+ if (err){
115
+ ToastAndroid . show(err,ToastAndroid . SHORT );
116
+ }else {
117
+ if (action === ' buttonClicked' ){
118
+ if (button === ' positive' ){
119
+ ToastAndroid . show(' 点击确定' ,ToastAndroid . SHORT );
120
+ }else if (button === ' negative' ){
121
+ ToastAndroid . show(' 点击取消' ,ToastAndroid . SHORT );
122
+ }
123
+ }
124
+ }
125
+ });
126
+ }
127
+
128
+ error (){
129
+ MyPop . showPopupWindow(null ,(err,action,button) = > {
130
+ if (err){
131
+ ToastAndroid . show(err,ToastAndroid . SHORT );
132
+ }else {
133
+ ToastAndroid . show(' action = ' + action + ' button = ' + button,ToastAndroid . SHORT );
134
+ }
135
+ });
136
+ }
137
+
138
+ render () {
139
+ return (
140
+ < View style= {styles. container}>
141
+ < Text style= {styles. welcome} onPress= {this . right}>
142
+ 正确示例
143
+ < / Text >
144
+ < Text style= {styles. welcome} onPress= {this . error}>
145
+ 错误示例
146
+ < / Text >
147
+ < / View >
148
+ );
149
+ }
150
+ }
151
+
152
+ const styles = StyleSheet.create ({
153
+ container : {
154
+ flex : 1 ,
155
+ justifyContent : 'center ',
156
+ alignItems : 'center ',
157
+ backgroundColor : '#F5FCFF ',
158
+ },
159
+ welcome : {
160
+ fontSize : 20 ,
161
+ textAlign : 'center ',
162
+ color : '#333333 ',
163
+ margin : 10 ,
164
+ },
165
+ });
166
+
167
+ AppRegistry.registerComponent ('PopupWindow ', () => PopupWindow);
168
+ ```
0 commit comments