Code Monkey home page Code Monkey logo

react-native-insta-story's Introduction

react-native-insta-story

Install

1. Step

npm install react-native-insta-story --save

or

yarn add react-native-insta-story

2. Step

cd ios && pod install

Import

import InstaStory from 'react-native-insta-story';

Props

Name Description Type Default Value
data Array of IUserStory. You can check from interfaces. object
unPressedBorderColor Unpressed border color of profile circle color red
pressedBorderColor Pressed border color of profile circle color grey
unPressedAvatarTextColor Unpressed avatar text color color red
pressedAvatarTextColor Pressed avatar text color color grey
onStorySeen Called each time story is seen function null
onClose Todo when close function null
onStart Todo when start function null
duration Per story duration seconds number 10
swipeText Text of swipe component string Swipe Up
renderSwipeUpComponent Render a custom swipe up component function
renderCloseComponent Render a custom close button function
renderTextComponent Render custom avatar text component function
avatarSize Size of avatar circle number 60
showAvatarText For show or hide avatar text. bool true
avatarTextStyle For avatar text style TextStyle
avatarImageStyle For avatar image style ImageStyle
avatarWrapperStyle For individual avatar wrapper style ViewStyle
avatarFlatListProps Horizontal avatar flat list props FlatListProps
loadedAnimationBarStyle For loaded animation bar style ViewStyle
unloadedAnimationBarStyle For unloaded animation bar style ViewStyle
animationBarContainerStyle For animation bar container style ViewStyle
storyUserContainerStyle For story item user container style ViewStyle
storyImageStyle For story image style ImageStyle
storyAvatarImageStyle For story avatar image style ImageStyle
storyContainerStyle For story container style ViewStyle

Usage

Basic

import InstaStory from 'react-native-insta-story';

const data = [
  {
    user_id: 1,
    user_image:
      'https://pbs.twimg.com/profile_images/1222140802475773952/61OmyINj.jpg',
    user_name: 'Ahmet Çağlar Durmuş',
    stories: [
      {
        story_id: 1,
        story_image:
          'https://image.freepik.com/free-vector/universe-mobile-wallpaper-with-planets_79603-600.jpg',
        swipeText: 'Custom swipe text for this story',
        onPress: () => console.log('story 1 swiped'),
      },
      {
        story_id: 2,
        story_image:
          'https://image.freepik.com/free-vector/mobile-wallpaper-with-fluid-shapes_79603-601.jpg',
      },
    ],
  },
  {
    user_id: 2,
    user_image:
      'https://images.unsplash.com/photo-1511367461989-f85a21fda167?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8cHJvZmlsZXxlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&w=1000&q=80',
    user_name: 'Test User',
    stories: [
      {
        story_id: 1,
        story_image:
          'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTjORKvjcbMRGYPR3QIs3MofoWkD4wHzRd_eg&usqp=CAU',
        swipeText: 'Custom swipe text for this story',
        onPress: () => console.log('story 1 swiped'),
      },
      {
        story_id: 2,
        story_image:
          'https://files.oyebesmartest.com/uploads/preview/vivo-u20-mobile-wallpaper-full-hd-(1)qm6qyz9v60.jpg',
        swipeText: 'Custom swipe text for this story',
        onPress: () => console.log('story 2 swiped'),
      },
    ],
  },
];

<InstaStory
  data={data}
  duration={10}
/>

Custom components

The render component functions are all passed item as a prop which is the current IUserStoryItem being displayed.

renderSwipeUpComponent and renderCloseComponent are both passed the onPress prop which is a function that closes the current story item modal and calls the IUserStoryItem.onPress function. onPress is passed so you could add other buttons. This is useful when adding a button which has it's own onPress prop, eg. a share button, next to the close button.

renderTextComponent is passed the profileName of the current story's user.

const data = [...sameDataAsBasicExampleAbove];

const [seenStories, setSeenStories] = useState(new Set());

const updateSeenStories = ({ story: { story_id } }) => {
  setSeenStories((prevSet) => {
    prevSet.add(storyId);
    return prevSet;
  });
};

const handleSeenStories = async (item) => {
  console.log(item);
  const storyIds = [];
  seenStories.forEach((storyId) => {
    if (storyId) storyIds.push(storyId);
  });
  if (storyIds.length > 0) {
    await fetch('myApi', {
      method: 'POST',
      body: JSON.stringify({ storyIds }),
    });
    seenStories.clear();
  }
};

<InstaStory
  data={data}
  duration={10}
  onStart={(item) => console.log(item)}
  onClose={handleSeenStories}
  onStorySeen={updateSeenStories}
  renderCloseComponent={({ item, onPress }) => (
    <View style={{ flexDirection: 'row' }}>
      <Button onPress={shareStory}>Share</Button>
      <Button onPress={onPress}>X</Button>
    </View>
  )}
  renderTextComponent={({ item, profileName }) => (
    <View>
      <Text>{profileName}</Text>
      <Text>{item.customProps?.yourCustomProp}</Text>
    </View>
  )}
  style={{ marginTop: 30 }}
/>

react-native-insta-story's People

Contributors

caglardurmus avatar eswr avatar ib3n avatar metehankurucu avatar olcaneristi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-insta-story's Issues

Custom Highlight button

i want to add a custom highlight button. How can i add that ?.

I tried to add it on renderCloseComponent but when click on that highlight button it closes the screen

#video support

thanks for a package that is easy to use and customizable please also add video support in the stories view.

Data from firebase

I'm trying to use data from firebase, but I'm constantly having problems, the last error I'm stuck on is
'TypeError: undefined is not a function (near '...selectedData.map...')' fetch data using hook useEffect

unable to use typescript under .js file

import type {IUserStory} from "./interfaces/IUserStory";
import type {IUserStoryItem} from "./interfaces/IUserStory";

I am unable to use the above line under .js file

Save seen

Hi, I would like to save data about viewed stories after unloading the application, is there such a possibility?

Android error, Working fine iOS

  • What went wrong:
    A problem occurred evaluating project ':react-native-insta-story'.

Plugin with id 'maven' not found

"react-native": "0.67.2",
"react-native-insta-story": "^1.1.7",

how to pause story

I have to do like when in open keyboard in renderSwipeUpComponent I want to pause story

DEFAULT_AVATAR

Hi. Thank you for that great package. It would be great if we could able to change DEFAULT_AVATAR with a prop.

License

Hello,

As this appears to be an open source project, the missing license info makes it basically not possible to use by others, as stated here https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository

However, without a license, the default copyright laws apply, meaning that you retain all rights to your source code and no one may reproduce, distribute, or create derivative works from your work. If you're creating an open source project, we strongly encourage you to include an open source license.

Could you please clarify this issue? And if it's intended for OSS, then could you kindly include the relevant file or update package.json with the "license" entry?

All the best and thank you for you great work!

Warning messages on opening any story

Firstly I would like to congrats you for this awesome work! ellerinize sağlık.

warning messages :

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

  • Move data fetching code or side effects to componentDidUpdate.
  • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
  • Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: %s, AndroidCubeEffect
at node_modules\react-native\Libraries\LogBox\LogBox.js:117:10 in registerWarning
at node_modules\react-native\Libraries\LogBox\LogBox.js:63:8 in warnImpl
at node_modules\react-native\Libraries\LogBox\LogBox.js:36:4 in console.warn
at node_modules\expo\build\environment\react-native-logs.fx.js:18:4 in warn
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:106:4 in printWarning
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:60:16 in warn
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5864:10 in ReactStrictModeWarnings.flushPendingUnsafeLifecycleWarnings
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19093:6 in flushRenderPhaseStrictModeWarningsInDEV
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18335:41 in commitRootImpl
at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18317:17 in commitRoot
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17697:12 in performSyncWorkOnRoot
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5321:31 in runWithPriority$argument_1
at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5316:21 in flushSyncCallbackQueueImpl
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5304:28 in flushSyncCallbackQueue
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17718:28 in batchedUpdates$1
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2492:29 in batchedUpdates
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2638:16 in _receiveRootNodeIDEvent
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:2767:27 in receiveTouches
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue

LogBox not in React Native < 0.62

Hello, I am trying to use it with React.Native 0.61.5, but LogBox is not implemented so I get an error.
What version can I download in order to be able to use it?
Thank you in advance.

I can't patch on package?

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-insta-story/src/StoryCircleListItem.tsx b/node_modules/react-native-insta-story/src/StoryCircleListItem.tsx
index c80e6d8..6bd1f6f 100644
--- a/node_modules/react-native-insta-story/src/StoryCircleListItem.tsx
+++ b/node_modules/react-native-insta-story/src/StoryCircleListItem.tsx
@@ -10,6 +10,7 @@ import {
 
 import { usePrevious } from './helpers/StateHelpers';
 import { IUserStory, StoryCircleListItemProps } from './interfaces';
+import Sizing from '../../../src/common/Sizing';
 
 import DEFAULT_AVATAR from './assets/images/no_avatar.png';
 
@@ -27,19 +28,23 @@ const StoryCircleListItem = ({
   avatarWrapperStyle,
 }: StoryCircleListItemProps) => {
   const [isPressed, setIsPressed] = useState(item?.seen);
+  const [isVerifiedUser, setIsVerifiedUser] = useState(false);
 
   const prevSeen = usePrevious(item?.seen);
+  console.log({item});
 
   useEffect(() => {
-    if (prevSeen != item?.seen) {
+    if (prevSeen !== item?.seen) {
       setIsPressed(item?.seen);
     }
-    // eslint-disable-next-line react-hooks/exhaustive-deps
-  }, [item?.seen]);
+  }, [item?.seen, prevSeen]);
+
+  useEffect(() => {
+    setIsVerifiedUser(item?.isVerified || false);
+  }, [item?.isVerified]);
 
   const _handleItemPress = (item: IUserStory) => {
     if (handleStoryItemPress) handleStoryItemPress(item);
-
     setIsPressed(true);
   };
 
@@ -47,6 +52,21 @@ const StoryCircleListItem = ({
 
   return (
     <View style={styles.container}>
+      {isVerifiedUser && (
+        <Image
+          source={require('../../../src/images/verified.png')}
+          style={{
+            width: Sizing.deviceWidth * 0.08,
+            height: Sizing.deviceHeight * 0.025,
+            borderRadius: 100,
+            position: 'absolute',
+            bottom: Sizing.deviceHeight * 0.065,
+            left: Sizing.deviceWidth * 0.093,
+            zIndex: 999,
+            resizeMode: 'contain',
+          }}
+        />
+      )}
       <TouchableOpacity
         onPress={() => _handleItemPress(item)}
         style={[
@@ -124,3 +144,4 @@ const styles = StyleSheet.create({
     fontSize: 11,
   },
 });
+

This issue body was partially generated by patch-package.

Unable to use resizeMode property in Image style

The resizeMode property cannot be used in the storyImageStyle, and the provided image source cannot be resized according to the screen. This issue may occur when the image does not match the screen dimensions.

Lagging Issue While Scrolling Through Instagram Stories

I am experiencing lag when scrolling through Instagram stories. The screen often stutters or freezes, affecting the smoothness of the navigation. This issue occurs consistently while stories in home screen, leading to a disrupted user experience. Could you please help address this performance problem?

> It's normal for it to work this way. Instagram uses it in the same way, we tried to emulate it. You cannot go back to before the story you clicked on, it is now your start story.

It's normal for it to work this way. Instagram uses it in the same way, we tried to emulate it. You cannot go back to before the story you clicked on, it is now your start story.

But in instagram you can go back to before story you clicked on it. Can you please try to add this in upcoming commit of yours, it will be very helpful. Thanks for the library and all the efforts you have put to make this good one.

Originally posted by @luckychdhr in #10 (comment)

Erros

I Tried to use but there is erros showing on the console.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.