@umituz/react-native-settings 1.3.6 → 1.3.8
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/package.json
CHANGED
|
@@ -16,7 +16,7 @@ import { List, Divider } from 'react-native-paper';
|
|
|
16
16
|
import { DeviceEventEmitter, Alert, View, TouchableOpacity, StyleSheet } from 'react-native';
|
|
17
17
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
18
18
|
|
|
19
|
-
import { useNavigation } from '@react-navigation/native';
|
|
19
|
+
import { useNavigation, CommonActions } from '@react-navigation/native';
|
|
20
20
|
import { useTheme, useAppDesignTokens } from '@umituz/react-native-design-system-theme';
|
|
21
21
|
import { ScreenLayout, AtomicIcon, AtomicText } from '@umituz/react-native-design-system';
|
|
22
22
|
import { SettingItem } from '../components/SettingItem';
|
|
@@ -143,12 +143,34 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
|
|
|
143
143
|
// Try to go back in current navigator first
|
|
144
144
|
if (navigation.canGoBack()) {
|
|
145
145
|
navigation.goBack();
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// If we can't go back in current navigator, try to find parent navigator
|
|
150
|
+
// This handles the case where Settings is the root screen of a stack
|
|
151
|
+
let parent = navigation.getParent();
|
|
152
|
+
let depth = 0;
|
|
153
|
+
const maxDepth = 5; // Safety limit to prevent infinite loops
|
|
154
|
+
|
|
155
|
+
// Traverse up the navigation tree to find a navigator that can go back
|
|
156
|
+
while (parent && depth < maxDepth) {
|
|
157
|
+
if (parent.canGoBack()) {
|
|
151
158
|
parent.goBack();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
parent = parent.getParent();
|
|
162
|
+
depth++;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// If no parent can go back, try using CommonActions to go back
|
|
166
|
+
// This is a fallback for edge cases
|
|
167
|
+
try {
|
|
168
|
+
navigation.dispatch(CommonActions.goBack());
|
|
169
|
+
} catch (error) {
|
|
170
|
+
// If all else fails, silently fail (close button just won't work)
|
|
171
|
+
/* eslint-disable-next-line no-console */
|
|
172
|
+
if (__DEV__) {
|
|
173
|
+
console.warn('[SettingsScreen] Could not navigate back:', error);
|
|
152
174
|
}
|
|
153
175
|
}
|
|
154
176
|
};
|
|
@@ -169,9 +191,30 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
|
|
|
169
191
|
if (navigation.canGoBack()) {
|
|
170
192
|
navigation.goBack();
|
|
171
193
|
} else {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
194
|
+
// Try to find parent navigator that can go back
|
|
195
|
+
let parent = navigation.getParent();
|
|
196
|
+
let depth = 0;
|
|
197
|
+
const maxDepth = 5;
|
|
198
|
+
|
|
199
|
+
while (parent && depth < maxDepth) {
|
|
200
|
+
if (parent.canGoBack()) {
|
|
201
|
+
parent.goBack();
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
parent = parent.getParent();
|
|
205
|
+
depth++;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Fallback to CommonActions
|
|
209
|
+
if (!parent || depth >= maxDepth) {
|
|
210
|
+
try {
|
|
211
|
+
navigation.dispatch(CommonActions.goBack());
|
|
212
|
+
} catch (error) {
|
|
213
|
+
/* eslint-disable-next-line no-console */
|
|
214
|
+
if (__DEV__) {
|
|
215
|
+
console.warn('[SettingsScreen] Could not navigate back:', error);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
175
218
|
}
|
|
176
219
|
}
|
|
177
220
|
// Small delay to ensure navigation completes
|
|
@@ -218,7 +261,7 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
|
|
|
218
261
|
hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
|
|
219
262
|
testID="close-settings-button"
|
|
220
263
|
>
|
|
221
|
-
<AtomicIcon name="X" size="lg" color="
|
|
264
|
+
<AtomicIcon name="X" size="lg" color="primary" />
|
|
222
265
|
</TouchableOpacity>
|
|
223
266
|
</View>
|
|
224
267
|
|