Skip to content

Commit af85e8d

Browse files
committed
feat: add IterableInboxIcon and IterableInboxSmartIcon components for enhanced icon support
1 parent b1decd7 commit af85e8d

File tree

9 files changed

+127
-14
lines changed

9 files changed

+127
-14
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
root: true,
3+
ignorePatterns: ['coverage/**/*'],
34
extends: [
45
'@react-native',
56
'plugin:react/recommended',

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Iterable. It supports JavaScript and TypeScript.
1717

1818
- [Iterable's React Native SDK](#iterables-react-native-sdk)
1919
- [Requirements](#requirements)
20+
- [React Native](#react-native)
21+
- [UI Components require additional peer dependencies](#ui-components-require-additional-peer-dependencies)
22+
- [Optional peer dependencies for enhanced UI](#optional-peer-dependencies-for-enhanced-ui)
23+
- [iOS](#ios)
24+
- [Android](#android)
2025
- [Architecture Support](#architecture-support)
2126
- [Installation](#installation)
2227
- [Features](#features)
@@ -34,22 +39,24 @@ Iterable. It supports JavaScript and TypeScript.
3439

3540
Iterable's React Native SDK relies on:
3641

37-
- **React Native**
38-
- [React Native 0.75+](https://github.com/facebook/react-native)
39-
- [React 18.1+](https://github.com/facebook/react)
42+
### React Native
43+
- [React Native 0.75+](https://github.com/facebook/react-native)
44+
- [React 18.1+](https://github.com/facebook/react)
4045

41-
_UI Components require additional peer dependencies_
42-
- [React Navigation 6+](https://github.com/react-navigation/react-navigation)
43-
- [React Native Safe Area Context 4+](https://github.com/th3rdwave/react-native-safe-area-context)
44-
- [React Native Vector Icons 10+](https://github.com/oblador/react-native-vector-icons)
45-
- [React Native WebView 13+](https://github.com/react-native-webview/react-native-webview)
46+
#### UI Components require additional peer dependencies
47+
- [React Navigation 6+](https://github.com/react-navigation/react-navigation)
48+
- [React Native Safe Area Context 4+](https://github.com/th3rdwave/react-native-safe-area-context)
49+
- [React Native WebView 13+](https://github.com/react-native-webview/react-native-webview)
4650

47-
- **iOS**
51+
#### Optional peer dependencies for enhanced UI
52+
- [React Native Vector Icons 10+](https://github.com/oblador/react-native-vector-icons) - Provides enhanced icons for the inbox component. If not installed, the SDK will use fallback Unicode symbols.
53+
54+
### iOS
4855
- Xcode 12+
4956
- [Deployment target 13.4+](https://help.apple.com/xcode/mac/current/#/deve69552ee5)
5057
- [Iterable's iOS SDK](https://github.com/Iterable/iterable-swift-sdk)
51-
52-
- **Android**
58+
- Swift 5
59+
### Android
5360
- [`minSdkVersion` 21+, `compileSdkVersion` 31+](https://medium.com/androiddevelopers/picking-your-compilesdkversion-minsdkversion-targetsdkversion-a098a0341ebd)
5461
- [Iterable's Android SDK](https://github.com/Iterable/iterable-android-sdk)
5562

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@
113113
"react": "*",
114114
"react-native": "*",
115115
"react-native-safe-area-context": "*",
116-
"react-native-vector-icons": "*",
117116
"react-native-webview": "*"
118117
},
119118
"peerDependenciesMeta": {
120119
"expo": {
121120
"optional": true
121+
},
122+
"react-native-vector-icons": {
123+
"optional": true
122124
}
123125
},
124126
"sideEffects": false,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Text, StyleSheet, type TextStyle } from 'react-native';
2+
3+
/**
4+
* Props for the IterableInboxIcon component.
5+
*/
6+
export interface IterableInboxIconProps {
7+
/**
8+
* The name of the icon to display.
9+
*/
10+
name: string;
11+
/**
12+
* The style to apply to the icon.
13+
*/
14+
style?: TextStyle;
15+
}
16+
17+
/**
18+
* A fallback icon component that uses Unicode symbols instead of vector icons.
19+
* This allows the inbox to work without requiring react-native-vector-icons.
20+
*/
21+
export const IterableInboxIcon = ({ name, style }: IterableInboxIconProps) => {
22+
// Map of common icon names to Unicode symbols
23+
const iconMap: Record<string, string> = {
24+
'chevron-back-outline': '‹',
25+
'chevron-back': '‹',
26+
'arrow-back': '←',
27+
'back': '←',
28+
};
29+
30+
const iconSymbol = iconMap[name] || '?';
31+
32+
return <Text style={[styles.icon, style]}>{iconSymbol}</Text>;
33+
};
34+
35+
const styles = StyleSheet.create({
36+
icon: {
37+
fontSize: 24,
38+
fontWeight: 'bold',
39+
textAlign: 'center',
40+
},
41+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
2+
import { type TextStyle } from 'react-native';
3+
4+
// Type for the vector icon component
5+
type VectorIconComponent = React.ComponentType<{
6+
name: string;
7+
style?: TextStyle;
8+
}>;
9+
10+
/**
11+
* Attempts to load the react-native-vector-icons module.
12+
* Returns null if the module is not available.
13+
*/
14+
export function tryLoadVectorIcons(): VectorIconComponent | null {
15+
try {
16+
return require('react-native-vector-icons/Ionicons').default;
17+
} catch {
18+
return null;
19+
}
20+
}

src/inbox/components/IterableInboxMessageDisplay.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
TouchableWithoutFeedback,
88
View,
99
} from 'react-native';
10-
import Icon from 'react-native-vector-icons/Ionicons';
10+
import { IterableInboxSmartIcon } from './IterableInboxSmartIcon';
1111
import { WebView, type WebViewMessageEvent } from 'react-native-webview';
1212

1313
import {
@@ -233,7 +233,7 @@ export const IterableInboxMessageDisplay = ({
233233
}}
234234
>
235235
<View style={styles.returnButton}>
236-
<Icon
236+
<IterableInboxSmartIcon
237237
name="chevron-back-outline"
238238
style={styles.returnButtonIcon}
239239
/>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { type TextStyle } from 'react-native';
2+
3+
import { IterableInboxIcon } from './IterableInboxIcon';
4+
import { tryLoadVectorIcons } from './IterableInboxIconUtils';
5+
6+
/**
7+
* Props for the IterableInboxSmartIcon component.
8+
*/
9+
export interface IterableInboxSmartIconProps {
10+
/**
11+
* The name of the icon to display.
12+
*/
13+
name: string;
14+
/**
15+
* The style to apply to the icon.
16+
*/
17+
style?: TextStyle;
18+
}
19+
20+
/**
21+
* A smart icon component that attempts to use react-native-vector-icons if available,
22+
* otherwise falls back to Unicode symbols.
23+
*/
24+
export const IterableInboxSmartIcon = ({
25+
name,
26+
style,
27+
}: IterableInboxSmartIconProps) => {
28+
const VectorIcon = tryLoadVectorIcons();
29+
30+
if (VectorIcon) {
31+
return <VectorIcon name={name} style={style} />;
32+
}
33+
34+
// Fallback to Unicode symbols
35+
return <IterableInboxIcon name={name} style={style} />;
36+
};

src/inbox/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export * from './IterableInbox';
22
export * from './IterableInboxEmptyState';
3+
export * from './IterableInboxIcon';
4+
export * from './IterableInboxSmartIcon';
35
export * from './IterableInboxMessageCell';
46
export * from './IterableInboxMessageDisplay';
57
export * from './IterableInboxMessageList';

src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ export {
4444
IterableInbox,
4545
IterableInboxDataModel,
4646
IterableInboxEmptyState,
47+
IterableInboxIcon,
4748
IterableInboxMessageCell,
49+
IterableInboxSmartIcon,
4850
type IterableInboxCustomizations,
4951
type IterableInboxEmptyStateProps,
52+
type IterableInboxIconProps,
5053
type IterableInboxImpressionRowInfo,
5154
type IterableInboxMessageCellProps,
5255
type IterableInboxProps,
5356
type IterableInboxRowViewModel,
57+
type IterableInboxSmartIconProps,
5458
} from './inbox';

0 commit comments

Comments
 (0)