Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

67 unable to use local images #90

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ If you use video in your stories, please make sure you have `react-native-video`
To use the `InstagramStories` component, you need to import it in your React Native application and include it in your JSX code. Here's an example of how to use it:

```jsx
import React from 'react';
import React, { useRef } from 'react';
import { View } from 'react-native';
import InstagramStories from '@birdwingo/react-native-instagram-stories';
import InstagramStories, { InstagramStoriesPublicMethods } from '@birdwingo/react-native-instagram-stories';

const YourComponent = () => {

// to use public methods:
const ref = useRef( null ); // if using typescript - useRef<InstagramStoriesPublicMethods>( null )

const stories = [{
id: 'user1',
Expand All @@ -65,13 +68,18 @@ const YourComponent = () => {
// ...
]}, // ...
];

// usage of public method
const setStories = () => ref.current?.setStories( stories );

return (
<View>
<InstagramStories
ref={ref}
stories={stories}
// ...
/>
<Pressable onPress={setStories}>{...}</Pressable>
</View>
);
};
Expand Down Expand Up @@ -144,7 +152,7 @@ export default YourComponent;
Parameter | Type | Required
-----------------------|----------------------------------------|----------------
`id` | string | true
`imgUrl` | string | false
`avatarSource` | ImageProps['source'] | false
`renderAvatar` | () => ReactNode | false
`renderStoryHeader` | () => ReactNode | false
`name` | string | false
Expand Down
3 changes: 2 additions & 1 deletion src/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const AnimatedImage = Animated.createAnimatedComponent( Image );

const StoryAvatar: FC<StoryAvatarProps> = ( {
id,
avatarSource,
imgUrl,
name,
stories,
Expand Down Expand Up @@ -52,7 +53,7 @@ const StoryAvatar: FC<StoryAvatarProps> = ( {
<TouchableOpacity activeOpacity={0.6} onPress={onPress} testID={`${id}StoryAvatar${stories.length}Story`}>
<Loader loading={isLoading} color={loaderColor} size={size + AVATAR_OFFSET * 2} />
<AnimatedImage
source={{ uri: imgUrl }}
source={avatarSource ?? { uri: imgUrl }}
style={[
AvatarStyles.avatar,
imageAnimatedStyles,
Expand Down
6 changes: 3 additions & 3 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { StoryHeaderProps } from '../../core/dto/componentsDTO';
import Close from '../Icon/close';

const StoryHeader: FC<StoryHeaderProps> = ( {
imgUrl, name, onClose, avatarSize, textStyle, closeColor, headerStyle,
avatarSource, imgUrl, name, onClose, avatarSize, textStyle, closeColor, headerStyle,
headerContainerStyle, renderStoryHeader,
} ) => {

Expand All @@ -34,9 +34,9 @@ const StoryHeader: FC<StoryHeaderProps> = ( {
]}
>
<View style={[ HeaderStyles.left, headerStyle ]}>
{Boolean( imgUrl ) && (
{( Boolean( avatarSource ) || Boolean( imgUrl ) ) && (
<View style={[ HeaderStyles.avatar, { borderRadius: styles.borderRadius } ]}>
<Image source={{ uri: imgUrl }} style={styles} />
<Image source={avatarSource ?? { uri: imgUrl }} style={styles} />
</View>
)}
{Boolean( name ) && <Text style={textStyle}>{name}</Text>}
Expand Down
3 changes: 2 additions & 1 deletion src/components/InstagramStories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ const InstagramStories = forwardRef<InstagramStoriesPublicMethods, InstagramStor
<>
{!hideAvatarList && (
<ScrollView horizontal {...listContainerProps} {...avatarListContainerProps} contentContainerStyle={[ listContainerStyle, avatarListContainerStyle ]} testID="storiesList">
{data.map( ( story ) => story.renderAvatar?.() ?? ( story.imgUrl && (
{data.map( ( story ) => story.renderAvatar?.()
?? ( ( story.avatarSource || story.imgUrl ) && (
<StoryAvatar
{...story}
loadingStory={loadingStory}
Expand Down
1 change: 1 addition & 0 deletions src/core/dto/componentsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface StoryProgressItemProps extends Omit<StoryProgressProps, 'length
}

export interface StoryHeaderProps {
avatarSource?: ImageProps['source'];
imgUrl?: string;
name?: string;
avatarSize: number;
Expand Down
4 changes: 4 additions & 0 deletions src/core/dto/instagramStoriesDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export interface StoryItemProps {

export interface InstagramStoryProps {
id: string;
/**
* @deprecated Use {@link avatarSource} instead (set avatarSource to {uri: 'your url'}).
*/
imgUrl?: string;
avatarSource?: ImageProps['source'];
renderAvatar?: () => ReactNode;
renderStoryHeader?: () => ReactNode;
name?: string;
Expand Down
Loading