@umituz/react-native-settings 1.3.5 → 1.3.7

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-settings",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "Settings management for React Native apps - user preferences, theme, language, notifications",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -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';
@@ -140,8 +140,38 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
140
140
  };
141
141
 
142
142
  const handleClose = () => {
143
+ // Try to go back in current navigator first
143
144
  if (navigation.canGoBack()) {
144
145
  navigation.goBack();
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()) {
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);
174
+ }
145
175
  }
146
176
  };
147
177
 
@@ -157,8 +187,36 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
157
187
  await onboardingStore.reset();
158
188
  // Emit event to trigger navigation to onboarding
159
189
  DeviceEventEmitter.emit('reset-onboarding');
160
- // Close settings first
161
- navigation.goBack();
190
+ // Close settings first - try parent navigator if current can't go back
191
+ if (navigation.canGoBack()) {
192
+ navigation.goBack();
193
+ } else {
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
+ }
218
+ }
219
+ }
162
220
  // Small delay to ensure navigation completes
163
221
  setTimeout(() => {
164
222
  DeviceEventEmitter.emit('show-onboarding');