Commit 172a7bb
authored
fix(Android, Tabs): Fix tabs icons loading in release mode (#3413)
## Description
This PR improves the approach to loading image assets used as tab icons,
addressing issues with inconsistent or unreliable URI resolution -
particularly around local resources and assets in Android builds (debug
vs. release).
Previously, the image loading logic assumed that assets would always be
bundled with a `_` prefix in release builds. However, this is not a
reliable assumption and can break under certain project setups or custom
bundling configurations. Assets are now resolved directly using the
appropriate `android.resource` or `android_asset` URI schemes.
Additionally, now I'm resolving both drawable and raw into the
`res:/<id>` URI format before being converted to the proper
`android.resource://` URI expected by Fresco. This ensures consistent
behavior regardless of resource type.
This change ensures that both local resources and bundled assets are
correctly rendered as tab icons across different build variants, without
relying on unstable heuristics.
Fixes
#3399
## Changes
- Updated the approach in TabsImageLoader
## Screenshots / GIFs
Here you can add screenshots / GIFs documenting your change.
You can add before / after section if you're changing some behavior.
### Before
Debug:
<img width="325" height="747" alt="debug-before"
src="https://github.com/user-attachments/assets/22af3dde-e5c2-4596-82d8-71bff06d03e5"
/>
Release:
<img width="325" height="746" alt="release-before"
src="https://github.com/user-attachments/assets/9dfae14a-7858-45f2-84ca-75a81bb674ed"
/>
### After
Debug:
<img width="322" height="748" alt="debug-after"
src="https://github.com/user-attachments/assets/3c2b2da6-4927-47ff-b779-2e173dbb17c7"
/>
Release:
<img width="328" height="745" alt="release-after"
src="https://github.com/user-attachments/assets/e5d00ff9-49ff-440e-8c0f-6eea21643254"
/>
## Test code and steps to reproduce
It's working fine it both debug and release in our examples, before and
after applying these changes. Therefore, I was testing it on a separate
application with this code snippet:
```js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createNativeBottomTabNavigator } from '@react-navigation/bottom-tabs/unstable';
import { NavigationContainer } from '@react-navigation/native';
const Tab = createNativeBottomTabNavigator();
function App() {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen
name="Home"
component={HomeScreen}
options={{
tabBarIcon: {
type: "drawableResource",
name: "custom_home_icon"
},
}}
/>
<Tab.Screen
name="Profile"
component={ProfileScreen}
options={{
tabBarIcon: {
type: 'image',
source: require('./assets/icon_fill.png'),
},
}}
/>
<Tab.Screen
name="Settings"
component={SettingsScreen}
options={{
tabBarIcon: {
type: 'image',
source: require('./assets/icon.png'),
},
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
}
const HomeScreen = () => (
<View style={styles.container}>
<Text>Home</Text>
</View>
);
const ProfileScreen = () => (
<View style={styles.container}>
<Text>Profile</Text>
</View>
);
const SettingsScreen = () => (
<View style={styles.container}>
<Text>Settings</Text>
</View>
);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
});
export default App;
```
I'm adding `custom_home_icon` via android resource manager and other
icons via `assets/` directory
## Checklist
- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes1 parent cf5dc93 commit 172a7bb
File tree
1 file changed
+82
-41
lines changed- android/src/main/java/com/swmansion/rnscreens/gamma/tabs/image
1 file changed
+82
-41
lines changedLines changed: 82 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | | - | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | | - | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | | - | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | 43 | | |
52 | 44 | | |
53 | | - | |
| 45 | + | |
54 | 46 | | |
55 | 47 | | |
56 | 48 | | |
| |||
78 | 70 | | |
79 | 71 | | |
80 | 72 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
93 | 86 | | |
94 | | - | |
95 | | - | |
96 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
97 | 103 | | |
98 | | - | |
99 | | - | |
100 | 104 | | |
101 | 105 | | |
102 | | - | |
103 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
104 | 110 | | |
105 | 111 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
110 | 132 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
114 | 155 | | |
0 commit comments