rn-android-blur 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # rn-android-blur
2
+
3
+ React Native библиотека для создания эффекта размытия фона на Android устройствах.
4
+
5
+ ## Требования
6
+
7
+ - React Native >= 0.60.0
8
+ - Android API Level 31+ (Android 12+)
9
+ - Kotlin
10
+
11
+ ## Установка
12
+
13
+ ```bash
14
+ npm install rn-android-blur
15
+ # или
16
+ yarn add rn-android-blur
17
+ ```
18
+
19
+ ### Настройка Android
20
+
21
+ 1. Откройте файл `android/settings.gradle` и добавьте:
22
+
23
+ ```gradle
24
+ include ':rn-android-blur'
25
+ project(':rn-android-blur').projectDir = new File(rootProject.projectDir, '../node_modules/rn-android-blur/android')
26
+ ```
27
+
28
+ 2. Откройте файл `android/app/build.gradle` и добавьте в секцию `dependencies`:
29
+
30
+ ```gradle
31
+ dependencies {
32
+ // ... другие зависимости
33
+ implementation project(':rn-android-blur')
34
+ }
35
+ ```
36
+
37
+ 3. Откройте файл `android/app/src/main/java/.../MainApplication.java` (или `MainApplication.kt`) и добавьте импорт и регистрацию пакета:
38
+
39
+ **Для Java:**
40
+ ```java
41
+ import com.rnandroidblur.BlurPackage;
42
+
43
+ public class MainApplication extends Application implements ReactApplication {
44
+ // ...
45
+
46
+ @Override
47
+ protected List<ReactPackage> getPackages() {
48
+ return Arrays.<ReactPackage>asList(
49
+ new MainReactPackage(),
50
+ new BlurPackage() // Добавьте эту строку
51
+ );
52
+ }
53
+ }
54
+ ```
55
+
56
+ **Для Kotlin:**
57
+ ```kotlin
58
+ import com.rnandroidblur.BlurPackage
59
+
60
+ class MainApplication : Application(), ReactApplication {
61
+ // ...
62
+
63
+ override fun getPackages(): List<ReactPackage> {
64
+ return listOf(
65
+ MainReactPackage(),
66
+ BlurPackage() // Добавьте эту строку
67
+ )
68
+ }
69
+ }
70
+ ```
71
+
72
+ 4. Выполните синхронизацию Gradle и пересоберите проект:
73
+
74
+ ```bash
75
+ cd android
76
+ ./gradlew clean
77
+ cd ..
78
+ npx react-native run-android
79
+ ```
80
+
81
+ ## Использование
82
+
83
+ ### Базовый пример
84
+
85
+ ```tsx
86
+ import React from 'react';
87
+ import { View, Text, StyleSheet } from 'react-native';
88
+ import { BlurView } from 'rn-android-blur';
89
+
90
+ export default function App() {
91
+ return (
92
+ <View style={styles.container}>
93
+ {/* Контент, который будет размыт */}
94
+ <View style={styles.background}>
95
+ <Text style={styles.text}>Фоновый контент</Text>
96
+ </View>
97
+
98
+ {/* BlurView поверх фона */}
99
+ <BlurView style={styles.blur} radius={20}>
100
+ <Text style={styles.blurText}>Размытый контент</Text>
101
+ </BlurView>
102
+ </View>
103
+ );
104
+ }
105
+
106
+ const styles = StyleSheet.create({
107
+ container: {
108
+ flex: 1,
109
+ },
110
+ background: {
111
+ position: 'absolute',
112
+ width: '100%',
113
+ height: '100%',
114
+ backgroundColor: '#4A90E2',
115
+ justifyContent: 'center',
116
+ alignItems: 'center',
117
+ },
118
+ text: {
119
+ fontSize: 24,
120
+ color: 'white',
121
+ },
122
+ blur: {
123
+ position: 'absolute',
124
+ bottom: 0,
125
+ left: 0,
126
+ right: 0,
127
+ height: 200,
128
+ justifyContent: 'center',
129
+ alignItems: 'center',
130
+ },
131
+ blurText: {
132
+ fontSize: 18,
133
+ color: 'white',
134
+ fontWeight: 'bold',
135
+ },
136
+ });
137
+ ```
138
+
139
+ ### Пример с модальным окном
140
+
141
+ ```tsx
142
+ import React, { useState } from 'react';
143
+ import { View, Text, StyleSheet, Modal, TouchableOpacity } from 'react-native';
144
+ import { BlurView } from 'rn-android-blur';
145
+
146
+ export default function ModalExample() {
147
+ const [visible, setVisible] = useState(false);
148
+
149
+ return (
150
+ <View style={styles.container}>
151
+ <TouchableOpacity
152
+ style={styles.button}
153
+ onPress={() => setVisible(true)}
154
+ >
155
+ <Text style={styles.buttonText}>Открыть модальное окно</Text>
156
+ </TouchableOpacity>
157
+
158
+ <Modal
159
+ visible={visible}
160
+ transparent={true}
161
+ animationType="fade"
162
+ onRequestClose={() => setVisible(false)}
163
+ >
164
+ <BlurView style={styles.modalOverlay} radius={25}>
165
+ <View style={styles.modalContent}>
166
+ <Text style={styles.modalTitle}>Модальное окно</Text>
167
+ <Text style={styles.modalText}>
168
+ Это содержимое отображается поверх размытого фона
169
+ </Text>
170
+ <TouchableOpacity
171
+ style={styles.closeButton}
172
+ onPress={() => setVisible(false)}
173
+ >
174
+ <Text style={styles.closeButtonText}>Закрыть</Text>
175
+ </TouchableOpacity>
176
+ </View>
177
+ </BlurView>
178
+ </Modal>
179
+ </View>
180
+ );
181
+ }
182
+
183
+ const styles = StyleSheet.create({
184
+ container: {
185
+ flex: 1,
186
+ justifyContent: 'center',
187
+ alignItems: 'center',
188
+ backgroundColor: '#f0f0f0',
189
+ },
190
+ button: {
191
+ backgroundColor: '#4A90E2',
192
+ padding: 15,
193
+ borderRadius: 8,
194
+ },
195
+ buttonText: {
196
+ color: 'white',
197
+ fontSize: 16,
198
+ fontWeight: 'bold',
199
+ },
200
+ modalOverlay: {
201
+ flex: 1,
202
+ justifyContent: 'center',
203
+ alignItems: 'center',
204
+ backgroundColor: 'rgba(0, 0, 0, 0.3)',
205
+ },
206
+ modalContent: {
207
+ backgroundColor: 'white',
208
+ borderRadius: 12,
209
+ padding: 24,
210
+ width: '80%',
211
+ alignItems: 'center',
212
+ },
213
+ modalTitle: {
214
+ fontSize: 24,
215
+ fontWeight: 'bold',
216
+ marginBottom: 12,
217
+ },
218
+ modalText: {
219
+ fontSize: 16,
220
+ textAlign: 'center',
221
+ marginBottom: 20,
222
+ color: '#666',
223
+ },
224
+ closeButton: {
225
+ backgroundColor: '#4A90E2',
226
+ padding: 12,
227
+ borderRadius: 8,
228
+ width: '100%',
229
+ alignItems: 'center',
230
+ },
231
+ closeButtonText: {
232
+ color: 'white',
233
+ fontSize: 16,
234
+ fontWeight: 'bold',
235
+ },
236
+ });
237
+ ```
238
+
239
+ ### Пример с навигационной панелью
240
+
241
+ ```tsx
242
+ import React from 'react';
243
+ import { View, Text, StyleSheet, ScrollView } from 'react-native';
244
+ import { BlurView } from 'rn-android-blur';
245
+
246
+ export default function NavigationExample() {
247
+ return (
248
+ <View style={styles.container}>
249
+ <ScrollView style={styles.scrollView}>
250
+ {Array.from({ length: 20 }).map((_, index) => (
251
+ <View key={index} style={styles.item}>
252
+ <Text style={styles.itemText}>Элемент {index + 1}</Text>
253
+ </View>
254
+ ))}
255
+ </ScrollView>
256
+
257
+ {/* Размытая навигационная панель */}
258
+ <BlurView style={styles.navBar} radius={15}>
259
+ <View style={styles.navContent}>
260
+ <Text style={styles.navTitle}>Заголовок</Text>
261
+ </View>
262
+ </BlurView>
263
+ </View>
264
+ );
265
+ }
266
+
267
+ const styles = StyleSheet.create({
268
+ container: {
269
+ flex: 1,
270
+ backgroundColor: '#f5f5f5',
271
+ },
272
+ scrollView: {
273
+ flex: 1,
274
+ },
275
+ item: {
276
+ padding: 20,
277
+ borderBottomWidth: 1,
278
+ borderBottomColor: '#e0e0e0',
279
+ backgroundColor: 'white',
280
+ },
281
+ itemText: {
282
+ fontSize: 16,
283
+ },
284
+ navBar: {
285
+ position: 'absolute',
286
+ top: 0,
287
+ left: 0,
288
+ right: 0,
289
+ height: 100,
290
+ paddingTop: 40,
291
+ justifyContent: 'flex-end',
292
+ },
293
+ navContent: {
294
+ padding: 16,
295
+ },
296
+ navTitle: {
297
+ fontSize: 20,
298
+ fontWeight: 'bold',
299
+ color: 'white',
300
+ },
301
+ });
302
+ ```
303
+
304
+ ## API
305
+
306
+ ### BlurView
307
+
308
+ Компонент для создания эффекта размытия.
309
+
310
+ #### Props
311
+
312
+ | Prop | Type | Default | Description |
313
+ |------|------|---------|-------------|
314
+ | `radius` | `number` | `20` | Радиус размытия (0-25). Чем больше значение, тем сильнее размытие. |
315
+ | `style` | `ViewStyle` | - | Стили для компонента (наследуется от `ViewProps`) |
316
+ | `children` | `ReactNode` | - | Дочерние элементы |
317
+
318
+ #### Примечания
319
+
320
+ - Эффект размытия работает только на Android 12+ (API Level 31+)
321
+ - На более старых версиях Android компонент будет отображаться без эффекта размытия
322
+ - Компонент наследует все стандартные props от `View` из React Native
323
+
324
+ ## Ограничения
325
+
326
+ - Работает только на Android 12+ (API Level 31+)
327
+ - Использует нативный API `RenderEffect`, который доступен только на новых версиях Android
328
+ - На iOS не работает (требуется отдельная реализация)
329
+
330
+ ## Лицензия
331
+
332
+ MIT
333
+
@@ -0,0 +1,52 @@
1
+ buildscript {
2
+ ext.kotlin_version = '1.9.0'
3
+ repositories {
4
+ google()
5
+ mavenCentral()
6
+ }
7
+ dependencies {
8
+ classpath("com.android.tools.build:gradle:8.1.0")
9
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
10
+ }
11
+ }
12
+
13
+ apply plugin: 'com.android.library'
14
+ apply plugin: 'kotlin-android'
15
+
16
+ android {
17
+ compileSdkVersion 34
18
+
19
+ defaultConfig {
20
+ minSdkVersion 31
21
+ targetSdkVersion 34
22
+ }
23
+
24
+ buildTypes {
25
+ release {
26
+ minifyEnabled false
27
+ }
28
+ }
29
+
30
+ compileOptions {
31
+ sourceCompatibility JavaVersion.VERSION_1_8
32
+ targetCompatibility JavaVersion.VERSION_1_8
33
+ }
34
+
35
+ kotlinOptions {
36
+ jvmTarget = '1.8'
37
+ }
38
+ }
39
+
40
+ repositories {
41
+ mavenCentral()
42
+ google()
43
+ maven {
44
+ url("$rootDir/../node_modules/react-native/android")
45
+ }
46
+ }
47
+
48
+ dependencies {
49
+ implementation 'com.facebook.react:react-native:+'
50
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
51
+ }
52
+
@@ -0,0 +1,13 @@
1
+ package com.rnandroidblur
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+ class BlurPackage : ReactPackage {
9
+ override fun createNativeModules(reactContext: ReactApplicationContext) = emptyList<NativeModule>()
10
+
11
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
12
+ listOf(BlurViewManager())
13
+ }
@@ -0,0 +1,25 @@
1
+ package com.rnandroidblur
2
+
3
+ import android.content.Context
4
+ import android.graphics.RenderEffect
5
+ import android.graphics.Shader
6
+ import android.os.Build
7
+ import android.util.AttributeSet
8
+ import android.widget.FrameLayout
9
+
10
+ class BlurView @JvmOverloads constructor(
11
+ context: Context,
12
+ attrs: AttributeSet? = null
13
+ ) : FrameLayout(context, attrs) {
14
+
15
+ fun setBlur(radius: Float) {
16
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
17
+ val effect = RenderEffect.createBlurEffect(
18
+ radius,
19
+ radius,
20
+ Shader.TileMode.CLAMP
21
+ )
22
+ setRenderEffect(effect)
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,19 @@
1
+ package com.rnandroidblur
2
+
3
+ import com.facebook.react.uimanager.SimpleViewManager
4
+ import com.facebook.react.uimanager.ThemedReactContext
5
+ import com.facebook.react.uimanager.annotations.ReactProp
6
+
7
+ class BlurViewManager : SimpleViewManager<BlurView>() {
8
+
9
+ override fun getName() = "RNBlurView"
10
+
11
+ override fun createViewInstance(reactContext: ThemedReactContext): BlurView {
12
+ return BlurView(reactContext)
13
+ }
14
+
15
+ @ReactProp(name = "radius", defaultFloat = 20f)
16
+ fun setRadius(view: BlurView, radius: Float) {
17
+ view.setBlur(radius)
18
+ }
19
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "rn-android-blur",
3
+ "version": "1.0.0",
4
+ "description": "React Native библиотека для размытия фона на Android",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "files": [
8
+ "src/",
9
+ "android/",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "keywords": [
16
+ "react-native",
17
+ "android",
18
+ "blur",
19
+ "blur-effect",
20
+ "native-module"
21
+ ],
22
+ "author": "Nikita Streltsov<i@chswe11.ru>",
23
+ "license": "MIT",
24
+ "peerDependencies": {
25
+ "react": ">=16.8.0",
26
+ "react-native": ">=0.60.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/react": "^18.0.0",
30
+ "@types/react-native": "^0.72.0",
31
+ "typescript": "^5.0.0"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": ""
36
+ }
37
+ }
38
+
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { requireNativeComponent, ViewProps } from 'react-native';
2
+
3
+ export type BlurViewProps = ViewProps & {
4
+ radius?: number;
5
+ };
6
+
7
+ export const BlurView = requireNativeComponent<BlurViewProps>('RNBlurView');