Skip to content

Commit 5136215

Browse files
feat: 添加详细文档和演示示例
1 parent 66f8975 commit 5136215

File tree

7 files changed

+193
-13
lines changed

7 files changed

+193
-13
lines changed

Example/ModalSample.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React, { Component } from "react";
2+
import {Text, TouchableHighlight, View, StyleSheet, TouchableWithoutFeedback, Image, StatusBar } from "react-native";
3+
import Modal from 'react-native-translucent-modal';
4+
5+
export default class ModalSample extends Component {
6+
state = {
7+
modalVisible: false,
8+
};
9+
10+
componentDidMount(){
11+
StatusBar.setTranslucent(true);
12+
StatusBar.setBackgroundColor('transparent');
13+
}
14+
15+
setModalVisible(visible) {
16+
this.setState({ modalVisible: visible });
17+
}
18+
19+
render() {
20+
return (
21+
<View style={{ backgroundColor: '#fff', flex: 1 }}>
22+
<Modal
23+
transparent={true}
24+
visible={this.state.modalVisible}
25+
onRequestClose={() => {
26+
alert("Modal has been closed.");
27+
this.setModalVisible(!this.state.modalVisible);
28+
}}
29+
>
30+
<TouchableWithoutFeedback onPress={() => this.setModalVisible(!this.state.modalVisible)}>
31+
<View style={styles.wrapper}>
32+
<View style={styles.container}>
33+
<Image source={require('./img/test.png')} style={{ width: 285, height: 176}}/>
34+
<Text style={styles.text}>领取礼包</Text>
35+
</View>
36+
</View>
37+
38+
</TouchableWithoutFeedback>
39+
</Modal>
40+
41+
42+
<View style={{flex: 1}}>
43+
<Image source={{uri: 'https://hbimg.huabanimg.com/637f9f357c4a83df1aa3cf2087a0b12c654e24bd3ef566-SYrIQb_fw658'}} style={ styles.image }/>
44+
<TouchableHighlight
45+
onPress={() => {
46+
this.setModalVisible(true);
47+
}}
48+
>
49+
<Text>Show Modal</Text>
50+
</TouchableHighlight>
51+
</View>
52+
53+
</View>
54+
);
55+
}
56+
}
57+
58+
const styles = StyleSheet.create({
59+
wrapper: {
60+
flex: 1,
61+
justifyContent: 'space-around',
62+
alignItems: 'center',
63+
backgroundColor: 'rgba(40, 40, 42, 0.6)',
64+
},
65+
66+
image: {
67+
height: 200,
68+
resizeMode: 'cover',
69+
},
70+
71+
text: {
72+
fontSize: 16,
73+
color: '#fff',
74+
},
75+
76+
container: {
77+
width: 285,
78+
height: 176,
79+
backgroundColor: '#efeff2',
80+
overflow: 'hidden',
81+
alignItems: 'center',
82+
borderRadius: 12,
83+
},
84+
});

Example/img/test.png

113 KB
Loading

Example/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import {AppRegistry} from 'react-native';
6-
import App from './App';
6+
import App from './ModalSample';
77
import {name as appName} from './app.json';
88

99
AppRegistry.registerComponent(appName, () => App);

README-zh-rCN.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
# react-native-translucent-modal
3+
A library for React Native Translucent Modal On Android
4+
5+
### 背景
6+
react-native 提供的`Modal`组件在Android上显示时不能延伸到状态栏,为什呢? 这与Android的原生实现有关,`Modal`组件对应到Android原生是用`Dialog`实现,因为 dialog 本身也不会延伸到状态栏的。如何让`Modal`在Android 上的显示效果能像在ios 设备上一样呢?这就是本库所提供的。使用很简单,只需要一行代码即可。
7+
8+
### 效果对比
9+
10+
使用`react-native-translucent-modal`之前:
11+
12+
`splash`:
13+
14+
<img src="/screen-shot/screenshot-before.jpg" width = "50%" height = "70%" alt="before1" align=center />
15+
16+
>
17+
18+
`弹窗:`
19+
20+
<img src="/screen-shot/screenshot-pop-before.jpg" width = "50%" height = "70%" alt="before1" align=center />
21+
22+
>
23+
24+
使用`react-native-translucent-modal`之后:
25+
26+
`splash`:
27+
28+
<img src="/screen-shot/screenshot-after.jpg" width = "50%" height = "70%" alt="after1" align=center />
29+
30+
>
31+
`弹窗`:
32+
33+
<img src="/screen-shot/screenshot-pop-after.jpg" width = "50%" height = "70%" alt="after1" align=center />
34+
35+
### 安装
36+
37+
1、使用npm
38+
39+
```
40+
$ npm install react-native-translucent-modal -save
41+
```
42+
43+
或使用yarn
44+
45+
```
46+
$ yarn add react-native-translucent-modal
47+
```
48+
49+
2、然后link
50+
51+
```
52+
$ react-native react-native-translucent-modal
53+
```
54+
55+
### 使用
56+
57+
`react-native-translucent-modal` 的使用与 react-native 提供`Modal`的组件完全一样,他们的属性和方法完全相同,你只需要将`Modal`的引入方式更改一下即可,其他的完全不用变
58+
59+
```
60+
import { Modal } from "react-native";
61+
```
62+
63+
改为
64+
65+
```
66+
import Modal from 'react-native-translucent-modal';
67+
```
68+
69+
好了,就只需要更改这一行代码,你的`Modal`现在就可以延伸到状态栏了。
70+
71+
在ios端,仍然使用的是 `react-native` 提供的`Modal`组件,详情请看`MFTranslucentModal.ios.js`
72+
73+
74+

README.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,78 @@
11
# react-native-translucent-modal
2-
A library for React Native translucent modal
2+
A library for React Native Translucent Modal On Android
33

4-
### 背景
5-
react-native 提供的`Modal`组件在Android上显示时不能延伸到状态栏,为什呢? 这与Android的原生实现有关,`Modal`组件对应到Android原生是用`Dialog`实现,因为 dialog 本身也不会延伸到状态栏的。如何让`Modal`在Android 上的显示效果能像在ios 设备上一样呢?这就是本库所提供的。使用很简单,只需要一行代码即可。
4+
Chinese introduction:
5+
[中文文档介绍](/README-zh-rCN.md)
66

7-
### 效果对比
7+
### Background
8+
The `Modal` component provided by `react-native` does not extend to the status bar when displayed on Android. Why? This is related to the native implementation of Android. The `Modal` component corresponds to Android native implementation with `Dialog`, because the dialog itself does not extend to the status bar. How can I make `Modal` appear on Android like on an iOS device? This is what the library provides. It's very simple to use, just one line of code.
89

9-
使用`react-native-translucent-modal`之前:
10+
### Effect comparison
11+
12+
Before using `react-native-translucent-modal`
13+
14+
`splash`:
1015

1116
<img src="/screen-shot/screenshot-before.jpg" width = "50%" height = "70%" alt="before1" align=center />
1217

1318
>
14-
使用`react-native-translucent-modal`之后:
1519
20+
`Pop:`
21+
22+
<img src="/screen-shot/screenshot-pop-before.jpg" width = "50%" height = "70%" alt="before1" align=center />
23+
24+
>
25+
26+
After using `react-native-translucent-modal`
27+
28+
`splash`:
1629

1730
<img src="/screen-shot/screenshot-after.jpg" width = "50%" height = "70%" alt="after1" align=center />
1831

32+
>
33+
`Pop`:
34+
35+
<img src="/screen-shot/screenshot-pop-after.jpg" width = "50%" height = "70%" alt="after1" align=center />
36+
1937
### Setup
2038

21-
1、使用npm
39+
1、Use npm
2240

2341
```
2442
$ npm install react-native-translucent-modal -save
2543
```
2644

27-
或使用yarn
45+
Or use yarn
2846

2947
```
3048
$ yarn add react-native-translucent-modal
3149
```
3250

33-
2、然后link
51+
2、then link
3452

3553
```
3654
$ react-native react-native-translucent-modal
3755
```
3856

3957
### Usage
4058

41-
`react-native-translucent-modal` 的使用与 react-native 提供`Modal`的组件完全一样,他们的属性和方法完全相同,你只需要将`Modal`的引入方式更改一下即可,其他的完全不用变
59+
The use of `react-native-translucent-modal` is exactly the same as that of the react-native providing `Modal`. Their properties and methods are exactly the same. You only need to change the import of `Modal`, the other is completely Don't change
4260

4361
```
4462
import { Modal } from "react-native";
4563
```
4664

47-
改为
65+
change to
4866

4967
```
5068
import Modal from 'react-native-translucent-modal';
5169
```
5270

53-
好了,就只需要更改这一行代码,你的`Modal`现在就可以延伸到状态栏了。
71+
Ok, just change this line of code, your `Modal` can now be extended to the status bar.
72+
73+
On iOS devices, the `Modal` component provided by react native is still used., you can view the `MFTranslucentModal.ios.js` file for detail.
5474

5575

76+
### Thanks
5677

78+
thanks [react-native-modal-translucent](https://github.com/listenzz/react-native-modal-translucent) library for providing ideas
429 KB
Loading
446 KB
Loading

0 commit comments

Comments
 (0)