react-native-auto-positioned-popup 1.0.9 → 1.0.11

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 CHANGED
@@ -26,6 +26,107 @@ or
26
26
  yarn add react-native-auto-positioned-popup
27
27
  ```
28
28
 
29
+ ## Loading Source Code in Development
30
+
31
+ If you need to debug or develop with the source code directly instead of the compiled library files, you can configure your project to load the TypeScript source files. This is useful for debugging or when you need to make temporary modifications.
32
+
33
+ ### Configure Babel to Load Source Files
34
+
35
+ 1. Install the babel module resolver plugin if you haven't already:
36
+
37
+ ```bash
38
+ npm install --save-dev babel-plugin-module-resolver
39
+ ```
40
+
41
+ 2. Update your `babel.config.js` to redirect imports from the compiled lib files to the source files:
42
+
43
+ ```javascript
44
+ module.exports = {
45
+ presets: ['module:@react-native/babel-preset'],
46
+ plugins: [
47
+ [
48
+ require.resolve('babel-plugin-module-resolver'),
49
+ {
50
+ root: ['.', './src'],
51
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
52
+ alias: {
53
+ // Redirect react-native-auto-positioned-popup to source files
54
+ 'react-native-auto-positioned-popup': './node_modules/react-native-auto-positioned-popup/src',
55
+ 'react-native-auto-positioned-popup/lib/index': './node_modules/react-native-auto-positioned-popup/src/index.ts',
56
+ 'react-native-auto-positioned-popup/lib/AutoPositionedPopup': './node_modules/react-native-auto-positioned-popup/src/AutoPositionedPopup.tsx',
57
+ 'react-native-auto-positioned-popup/lib/AutoPositionedPopupProps': './node_modules/react-native-auto-positioned-popup/src/AutoPositionedPopupProps.ts',
58
+ 'react-native-auto-positioned-popup/lib/RootViewContext': './node_modules/react-native-auto-positioned-popup/src/RootViewContext.tsx',
59
+ 'react-native-auto-positioned-popup/lib/KeyboardManager': './node_modules/react-native-auto-positioned-popup/src/KeyboardManager.tsx',
60
+ 'react-native-auto-positioned-popup/lib/AutoPositionedPopup.style': './node_modules/react-native-auto-positioned-popup/src/AutoPositionedPopup.style.ts',
61
+ // If you also use react-native-advanced-flatlist
62
+ 'react-native-advanced-flatlist': './node_modules/react-native-advanced-flatlist/src',
63
+ 'react-native-advanced-flatlist/lib/index': './node_modules/react-native-advanced-flatlist/src/index.ts',
64
+ 'react-native-advanced-flatlist/lib/AdvancedFlatList': './node_modules/react-native-advanced-flatlist/src/AdvancedFlatList.tsx',
65
+ },
66
+ },
67
+ ],
68
+ // ... other plugins
69
+ ],
70
+ };
71
+ ```
72
+
73
+ 3. Clear the Metro bundler cache and restart:
74
+
75
+ ```bash
76
+ npx react-native start --reset-cache
77
+ ```
78
+
79
+ ### Conditional Loading (Advanced)
80
+
81
+ If you want to conditionally load source files only in certain environments (e.g., during development), you can add logic to your babel config:
82
+
83
+ ```javascript
84
+ const isDevelopment = process.env.NODE_ENV === 'development';
85
+ const useSourceFiles = process.env.USE_SOURCE_FILES === 'true';
86
+
87
+ const aliasConfig = (isDevelopment || useSourceFiles) ? {
88
+ // ... your source file aliases
89
+ } : {
90
+ // ... your production aliases
91
+ };
92
+
93
+ module.exports = {
94
+ presets: ['module:@react-native/babel-preset'],
95
+ plugins: [
96
+ [
97
+ require.resolve('babel-plugin-module-resolver'),
98
+ {
99
+ root: ['.', './src'],
100
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
101
+ alias: aliasConfig,
102
+ },
103
+ ],
104
+ ],
105
+ };
106
+ ```
107
+
108
+ ### TypeScript Configuration
109
+
110
+ When loading source files directly, ensure your `tsconfig.json` includes the necessary paths:
111
+
112
+ ```json
113
+ {
114
+ "compilerOptions": {
115
+ "paths": {
116
+ "react-native-auto-positioned-popup": ["./node_modules/react-native-auto-positioned-popup/src"],
117
+ "react-native-auto-positioned-popup/*": ["./node_modules/react-native-auto-positioned-popup/src/*"]
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ ### Notes
124
+
125
+ - Loading source files directly may impact build performance
126
+ - Remember to revert these changes before building for production
127
+ - Always clear Metro cache after changing babel configuration
128
+ - This approach is recommended only for development and debugging purposes
129
+
29
130
  ## Basic Usage
30
131
 
31
132
  First, wrap your app with the `RootViewProvider`:
@@ -47,12 +148,13 @@ Then use the `AutoPositionedPopup` component:
47
148
  ```tsx
48
149
  import React, { useState } from 'react';
49
150
  import { View } from 'react-native';
50
- import AutoPositionedPopup, { SelectedItem, Data } from 'react-native-auto-positioned-popup';
151
+ import RNAutoPositionedPopup from 'react-native-auto-positioned-popup';
152
+ import type {SelectedItem as RNSelectedItem, Data as AutoPositionedPopupData} from 'react-native-auto-positioned-popup';
51
153
 
52
154
  const MyComponent = () => {
53
- const [selectedItem, setSelectedItem] = useState<SelectedItem | undefined>();
155
+ const [selectedItem, setSelectedItem] = useState<RNSelectedItem | undefined>();
54
156
 
55
- const fetchData = async ({ pageIndex, pageSize, searchQuery }): Promise<Data | null> => {
157
+ const fetchData = async ({ pageIndex, pageSize, searchQuery }): Promise<AutoPositionedPopupData | null> => {
56
158
  // Your data fetching logic here
57
159
  return {
58
160
  items: [
@@ -67,7 +169,7 @@ const MyComponent = () => {
67
169
 
68
170
  return (
69
171
  <View style={{ padding: 20 }}>
70
- <AutoPositionedPopup
172
+ <RNAutoPositionedPopup
71
173
  tag="example-popup"
72
174
  placeholder="Select an option"
73
175
  selectedItem={selectedItem}
@@ -144,10 +246,11 @@ This example shows a complete implementation without search input, suitable for
144
246
  ```tsx
145
247
  import React, { useState } from 'react';
146
248
  import { View, Text, Image, StyleSheet } from 'react-native';
147
- import AutoPositionedPopup, { SelectedItem, Data, RootViewProvider } from 'react-native-auto-positioned-popup';
249
+ import RNAutoPositionedPopup, { RootViewProvider } from 'react-native-auto-positioned-popup';
250
+ import type {SelectedItem as RNSelectedItem, Data as AutoPositionedPopupData} from 'react-native-auto-positioned-popup';
148
251
 
149
252
  // Sample data type with color support
150
- interface ClinicItem extends SelectedItem {
253
+ interface ClinicItem extends RNSelectedItem {
151
254
  code: string;
152
255
  textColor: string;
153
256
  address?: string;
@@ -156,7 +259,7 @@ interface ClinicItem extends SelectedItem {
156
259
  const ClinicSelector = () => {
157
260
  const [selectedClinic, setSelectedClinic] = useState<ClinicItem | null>(null);
158
261
 
159
- const fetchClinics = async ({ pageIndex, pageSize }): Promise<Data | null> => {
262
+ const fetchClinics = async ({ pageIndex, pageSize }): Promise<AutoPositionedPopupData | null> => {
160
263
  // Simulate API call
161
264
  const mockClinics = [
162
265
  { id: '1', title: 'Main Clinic', code: 'MC001', textColor: '#4CAF50', address: '123 Main St' },
@@ -177,7 +280,7 @@ const ClinicSelector = () => {
177
280
  return (
178
281
  <RootViewProvider>
179
282
  <View style={styles.container}>
180
- <AutoPositionedPopup
283
+ <RNAutoPositionedPopup
181
284
  tag="clinic-selector"
182
285
  useTextInput={false}
183
286
  localSearch={false}
package/README_zh.md CHANGED
@@ -26,6 +26,107 @@ npm install react-native-auto-positioned-popup
26
26
  yarn add react-native-auto-positioned-popup
27
27
  ```
28
28
 
29
+ ## 在开发环境中加载源码
30
+
31
+ 如果你需要调试或直接使用源代码进行开发,而不是使用编译后的库文件,可以配置你的项目来加载 TypeScript 源文件。这在调试或需要临时修改时非常有用。
32
+
33
+ ### 配置 Babel 加载源文件
34
+
35
+ 1. 如果还没有安装,请先安装 babel 模块解析器插件:
36
+
37
+ ```bash
38
+ npm install --save-dev babel-plugin-module-resolver
39
+ ```
40
+
41
+ 2. 更新你的 `babel.config.js`,将导入从编译的 lib 文件重定向到源文件:
42
+
43
+ ```javascript
44
+ module.exports = {
45
+ presets: ['module:@react-native/babel-preset'],
46
+ plugins: [
47
+ [
48
+ require.resolve('babel-plugin-module-resolver'),
49
+ {
50
+ root: ['.', './src'],
51
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
52
+ alias: {
53
+ // 将 react-native-auto-positioned-popup 重定向到源文件
54
+ 'react-native-auto-positioned-popup': './node_modules/react-native-auto-positioned-popup/src',
55
+ 'react-native-auto-positioned-popup/lib/index': './node_modules/react-native-auto-positioned-popup/src/index.ts',
56
+ 'react-native-auto-positioned-popup/lib/AutoPositionedPopup': './node_modules/react-native-auto-positioned-popup/src/AutoPositionedPopup.tsx',
57
+ 'react-native-auto-positioned-popup/lib/AutoPositionedPopupProps': './node_modules/react-native-auto-positioned-popup/src/AutoPositionedPopupProps.ts',
58
+ 'react-native-auto-positioned-popup/lib/RootViewContext': './node_modules/react-native-auto-positioned-popup/src/RootViewContext.tsx',
59
+ 'react-native-auto-positioned-popup/lib/KeyboardManager': './node_modules/react-native-auto-positioned-popup/src/KeyboardManager.tsx',
60
+ 'react-native-auto-positioned-popup/lib/AutoPositionedPopup.style': './node_modules/react-native-auto-positioned-popup/src/AutoPositionedPopup.style.ts',
61
+ // 如果你也使用 react-native-advanced-flatlist
62
+ 'react-native-advanced-flatlist': './node_modules/react-native-advanced-flatlist/src',
63
+ 'react-native-advanced-flatlist/lib/index': './node_modules/react-native-advanced-flatlist/src/index.ts',
64
+ 'react-native-advanced-flatlist/lib/AdvancedFlatList': './node_modules/react-native-advanced-flatlist/src/AdvancedFlatList.tsx',
65
+ },
66
+ },
67
+ ],
68
+ // ... 其他插件
69
+ ],
70
+ };
71
+ ```
72
+
73
+ 3. 清除 Metro bundler 缓存并重启:
74
+
75
+ ```bash
76
+ npx react-native start --reset-cache
77
+ ```
78
+
79
+ ### 条件加载(高级用法)
80
+
81
+ 如果你想只在特定环境(例如开发环境)中有条件地加载源文件,可以在 babel 配置中添加逻辑:
82
+
83
+ ```javascript
84
+ const isDevelopment = process.env.NODE_ENV === 'development';
85
+ const useSourceFiles = process.env.USE_SOURCE_FILES === 'true';
86
+
87
+ const aliasConfig = (isDevelopment || useSourceFiles) ? {
88
+ // ... 你的源文件别名
89
+ } : {
90
+ // ... 你的生产环境别名
91
+ };
92
+
93
+ module.exports = {
94
+ presets: ['module:@react-native/babel-preset'],
95
+ plugins: [
96
+ [
97
+ require.resolve('babel-plugin-module-resolver'),
98
+ {
99
+ root: ['.', './src'],
100
+ extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
101
+ alias: aliasConfig,
102
+ },
103
+ ],
104
+ ],
105
+ };
106
+ ```
107
+
108
+ ### TypeScript 配置
109
+
110
+ 当直接加载源文件时,确保你的 `tsconfig.json` 包含必要的路径:
111
+
112
+ ```json
113
+ {
114
+ "compilerOptions": {
115
+ "paths": {
116
+ "react-native-auto-positioned-popup": ["./node_modules/react-native-auto-positioned-popup/src"],
117
+ "react-native-auto-positioned-popup/*": ["./node_modules/react-native-auto-positioned-popup/src/*"]
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ ### 注意事项
124
+
125
+ - 直接加载源文件可能会影响构建性能
126
+ - 记得在生产构建前恢复这些更改
127
+ - 更改 babel 配置后务必清除 Metro 缓存
128
+ - 此方法仅建议用于开发和调试目的
129
+
29
130
  ## 基本用法
30
131
 
31
132
  首先,使用 `RootViewProvider` 包裹你的应用:
@@ -47,12 +148,13 @@ const App = () => {
47
148
  ```tsx
48
149
  import React, { useState } from 'react';
49
150
  import { View } from 'react-native';
50
- import AutoPositionedPopup, { SelectedItem, Data } from 'react-native-auto-positioned-popup';
151
+ import RNAutoPositionedPopup from 'react-native-auto-positioned-popup';
152
+ import type {SelectedItem as RNSelectedItem, Data as AutoPositionedPopupData} from 'react-native-auto-positioned-popup';
51
153
 
52
154
  const MyComponent = () => {
53
- const [selectedItem, setSelectedItem] = useState<SelectedItem | undefined>();
155
+ const [selectedItem, setSelectedItem] = useState<RNSelectedItem | undefined>();
54
156
 
55
- const fetchData = async ({ pageIndex, pageSize, searchQuery }): Promise<Data | null> => {
157
+ const fetchData = async ({ pageIndex, pageSize, searchQuery }): Promise<AutoPositionedPopupData | null> => {
56
158
  // 你的数据获取逻辑
57
159
  return {
58
160
  items: [
@@ -67,7 +169,7 @@ const MyComponent = () => {
67
169
 
68
170
  return (
69
171
  <View style={{ padding: 20 }}>
70
- <AutoPositionedPopup
172
+ <RNAutoPositionedPopup
71
173
  tag="example-popup"
72
174
  placeholder="请选择一个选项"
73
175
  selectedItem={selectedItem}
@@ -144,10 +246,11 @@ export default MyComponent;
144
246
  ```tsx
145
247
  import React, { useState } from 'react';
146
248
  import { View, Text, Image, StyleSheet } from 'react-native';
147
- import AutoPositionedPopup, { SelectedItem, Data, RootViewProvider } from 'react-native-auto-positioned-popup';
249
+ import RNAutoPositionedPopup from 'react-native-auto-positioned-popup';
250
+ import type {SelectedItem as RNSelectedItem, Data as AutoPositionedPopupData} from 'react-native-auto-positioned-popup';
148
251
 
149
252
  // 支持颜色的数据类型示例
150
- interface ClinicItem extends SelectedItem {
253
+ interface ClinicItem extends RNSelectedItem {
151
254
  code: string;
152
255
  textColor: string;
153
256
  address?: string;
@@ -156,7 +259,7 @@ interface ClinicItem extends SelectedItem {
156
259
  const ClinicSelector = () => {
157
260
  const [selectedClinic, setSelectedClinic] = useState<ClinicItem | null>(null);
158
261
 
159
- const fetchClinics = async ({ pageIndex, pageSize }): Promise<Data | null> => {
262
+ const fetchClinics = async ({ pageIndex, pageSize }): Promise<AutoPositionedPopupData | null> => {
160
263
  // 模拟 API 调用
161
264
  const mockClinics = [
162
265
  { id: '1', title: '主诊所', code: 'MC001', textColor: '#4CAF50', address: '主街123号' },
@@ -177,7 +280,7 @@ const ClinicSelector = () => {
177
280
  return (
178
281
  <RootViewProvider>
179
282
  <View style={styles.container}>
180
- <AutoPositionedPopup
283
+ <RNAutoPositionedPopup
181
284
  tag="clinic-selector"
182
285
  useTextInput={false}
183
286
  localSearch={false}
@@ -422,4 +525,4 @@ MIT © [Stark](https://github.com/your-username)
422
525
  - 自动定位功能
423
526
  - 搜索支持
424
527
  - TypeScript 定义
425
- - 跨平台兼容性
528
+ - 跨平台兼容性
@@ -1,5 +1,5 @@
1
- import { ForwardRefExoticComponent, MemoExoticComponent } from 'react';
1
+ import React from 'react';
2
2
  import { AutoPositionedPopupProps } from './AutoPositionedPopupProps';
3
- declare const AutoPositionedPopup: MemoExoticComponent<ForwardRefExoticComponent<AutoPositionedPopupProps>>;
3
+ declare const AutoPositionedPopup: React.NamedExoticComponent<AutoPositionedPopupProps & React.RefAttributes<unknown>>;
4
4
  export default AutoPositionedPopup;
5
5
  //# sourceMappingURL=AutoPositionedPopup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AutoPositionedPopup.d.ts","sourceRoot":"","sources":["../src/AutoPositionedPopup.tsx"],"names":[],"mappings":"AAAA,OAAc,EAGZ,yBAAyB,EAEzB,mBAAmB,EAOpB,MAAM,OAAO,CAAC;AAef,OAAO,EAAC,wBAAwB,EAAqB,MAAM,4BAA4B,CAAC;AAoRxF,QAAA,MAAM,mBAAmB,EAAE,mBAAmB,CAC5C,yBAAyB,CAAC,wBAAwB,CAAC,CAkoBpD,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"AutoPositionedPopup.d.ts","sourceRoot":"","sources":["../src/AutoPositionedPopup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAYN,MAAM,OAAO,CAAC;AAcf,OAAO,EAAC,wBAAwB,EAAqB,MAAM,4BAA4B,CAAC;AAwRxF,QAAA,MAAM,mBAAmB,qFA2vBxB,CAAC;AAEF,eAAe,mBAAmB,CAAC"}