| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
110 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,64 @@ | |||
| 1 | + # Sendbird React Native Hook + Local caching sample | ||
| 2 | + | ||
| 3 | + Sendbird React Native sample using [Sendbird SDK](https://github.com/sendbird/SendBird-SDK-JavaScript). | ||
| 4 | + | ||
| 5 | + ## Prerequisite | ||
| 6 | + | ||
| 7 | + - [Node](https://nodejs.org/en/) | ||
| 8 | + - [NPM](https://www.npmjs.com/) | ||
| 9 | + - [Cocoapods](https://cocoapods.org/) | ||
| 10 | + - [XCode](https://developer.apple.com/xcode) | ||
| 11 | + - [XCode Command Line Tools](https://facebook.github.io/react-native/docs/getting-started.html#xcode) | ||
| 12 | + - [Android Studio](https://developer.android.com/studio/) (+Android SDK/Google API) | ||
| 13 | + | ||
| 14 | + ## Run the sample | ||
| 15 | + | ||
| 16 | + 1. Install React Native CLI | ||
| 17 | + | ||
| 18 | + npm install -g react-native-cli | ||
| 19 | + | ||
| 20 | + 2. Install required packages | ||
| 21 | + | ||
| 22 | + npm install | ||
| 23 | + | ||
| 24 | + 3. (iOS only) Pod install | ||
| 25 | + | ||
| 26 | + cd ios | ||
| 27 | + pod install | ||
| 28 | + pod update | ||
| 29 | + | ||
| 30 | + 4. (iOS only) Add library in XCode | ||
| 31 | + | ||
| 32 | + - Open XCode and load workspace, you should load *.xcworkspace | ||
| 33 | + | ||
| 34 | + 5. Run the sample. Before starting, you should launch device emulator (or actual device) to run the sample in Android. This sample is not available for real device in iOS due to Apple Development Policy. In order to run React Native sample in real device, follow [React Native official guide](https://facebook.github.io/react-native/docs/running-on-device.html) for your own setup | ||
| 35 | + | ||
| 36 | + npx react-native run-android | ||
| 37 | + npx react-native run-ios | ||
| 38 | + | ||
| 39 | + For iOS, you may also launch directly from Xcode | ||
| 40 | + | ||
| 41 | + You don't need to do manual linking, i.e. `react-native link <package-name>` | ||
| 42 | + | ||
| 43 | + | ||
| 44 | + ## Troubleshooting | ||
| 45 | + | ||
| 46 | + 1. General | ||
| 47 | + - After each of these you might want to rebuild the project and run* | ||
| 48 | + - You can run `npm run clear` from root directory, this might help to solve some issues and clean old builds | ||
| 49 | + - Sometimes it is advised to delete package-lock.json, but we do not recommend it for compatibility issues, do it at your own risk | ||
| 50 | + - Make sure you have prerequisite software installed before your run this app, they can be found here: https://facebook.github.io/react-native/docs/getting-started | ||
| 51 | + - Sometimes deleting node_modules folder and reinstalling the dependencies again helps | ||
| 52 | + 2. iOS | ||
| 53 | + - Clean the build Cmd+Shift+K, also just rebuilding without cleaning the build can work sometimes | ||
| 54 | + - Do `pod update` and then `pod install` in the ios/ folder | ||
| 55 | + - Delete the ios/build folder | ||
| 56 | + - It is better not to change any build phases, rules, settings in XCode, as it may cause further issues | ||
| 57 | + - It is better to not update packages in package.json, or ios/Pods, or Android packages versions | ||
| 58 | + - Or do it very carefully | ||
| 59 | + - If you have an issue/error try to Google that and follow the instructions | ||
| 60 | + 3. Android | ||
| 61 | + - If you run on real device, check if everything installed and especially Android studio | ||
| 62 | + - Check if your device is visible by `adb devices`, sometimes it may not work or have lags. In this case call: `adb kill-server` and `adb start-server` | ||
| 63 | + - You might build the project using `react-native run-android`, but if it fails you might need to run it with Android studio | ||
| 64 | + - If you can't load bundle from 8081 port, run `adb reverse tcp:8081 tcp:8081` and restart app. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + | ||
| 2 | + [android] | ||
| 3 | + target = Google Inc.:Google APIs:23 | ||
| 4 | + | ||
| 5 | + [maven_repositories] | ||
| 6 | + central = https://repo1.maven.org/maven2 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + module.exports = { | ||
| 2 | + root: true, | ||
| 3 | + extends: '@react-native-community', | ||
| 4 | + rules: { | ||
| 5 | + 'react-hooks/exhaustive-deps': 0, | ||
| 6 | + curly: 0, | ||
| 7 | + }, | ||
| 8 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,65 @@ | |||
| 1 | + [ignore] | ||
| 2 | + ; We fork some components by platform | ||
| 3 | + .*/*[.]android.js | ||
| 4 | + | ||
| 5 | + ; Ignore "BUCK" generated dirs | ||
| 6 | + <PROJECT_ROOT>/\.buckd/ | ||
| 7 | + | ||
| 8 | + ; Ignore polyfills | ||
| 9 | + node_modules/react-native/Libraries/polyfills/.* | ||
| 10 | + | ||
| 11 | + ; Flow doesn't support platforms | ||
| 12 | + .*/Libraries/Utilities/LoadingView.js | ||
| 13 | + | ||
| 14 | + [untyped] | ||
| 15 | + .*/node_modules/@react-native-community/cli/.*/.* | ||
| 16 | + | ||
| 17 | + [include] | ||
| 18 | + | ||
| 19 | + [libs] | ||
| 20 | + node_modules/react-native/interface.js | ||
| 21 | + node_modules/react-native/flow/ | ||
| 22 | + | ||
| 23 | + [options] | ||
| 24 | + emoji=true | ||
| 25 | + | ||
| 26 | + exact_by_default=true | ||
| 27 | + | ||
| 28 | + format.bracket_spacing=false | ||
| 29 | + | ||
| 30 | + module.file_ext=.js | ||
| 31 | + module.file_ext=.json | ||
| 32 | + module.file_ext=.ios.js | ||
| 33 | + | ||
| 34 | + munge_underscores=true | ||
| 35 | + | ||
| 36 | + module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1' | ||
| 37 | + module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub' | ||
| 38 | + | ||
| 39 | + suppress_type=$FlowIssue | ||
| 40 | + suppress_type=$FlowFixMe | ||
| 41 | + suppress_type=$FlowFixMeProps | ||
| 42 | + suppress_type=$FlowFixMeState | ||
| 43 | + | ||
| 44 | + [lints] | ||
| 45 | + sketchy-null-number=warn | ||
| 46 | + sketchy-null-mixed=warn | ||
| 47 | + sketchy-number=warn | ||
| 48 | + untyped-type-import=warn | ||
| 49 | + nonstrict-import=warn | ||
| 50 | + deprecated-type=warn | ||
| 51 | + unsafe-getters-setters=warn | ||
| 52 | + unnecessary-invariant=warn | ||
| 53 | + signature-verification-failure=warn | ||
| 54 | + | ||
| 55 | + [strict] | ||
| 56 | + deprecated-type | ||
| 57 | + nonstrict-import | ||
| 58 | + sketchy-null | ||
| 59 | + unclear-type | ||
| 60 | + unsafe-getters-setters | ||
| 61 | + untyped-import | ||
| 62 | + untyped-type-import | ||
| 63 | + | ||
| 64 | + [version] | ||
| 65 | + ^0.162.0 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,60 @@ | |||
| 1 | + # OSX | ||
| 2 | + # | ||
| 3 | + .DS_Store | ||
| 4 | + | ||
| 5 | + # Xcode | ||
| 6 | + # | ||
| 7 | + build/ | ||
| 8 | + *.pbxuser | ||
| 9 | + !default.pbxuser | ||
| 10 | + *.mode1v3 | ||
| 11 | + !default.mode1v3 | ||
| 12 | + *.mode2v3 | ||
| 13 | + !default.mode2v3 | ||
| 14 | + *.perspectivev3 | ||
| 15 | + !default.perspectivev3 | ||
| 16 | + xcuserdata | ||
| 17 | + *.xccheckout | ||
| 18 | + *.moved-aside | ||
| 19 | + DerivedData | ||
| 20 | + *.hmap | ||
| 21 | + *.ipa | ||
| 22 | + *.xcuserstate | ||
| 23 | + | ||
| 24 | + # Android/IntelliJ | ||
| 25 | + # | ||
| 26 | + build/ | ||
| 27 | + .idea | ||
| 28 | + .gradle | ||
| 29 | + local.properties | ||
| 30 | + *.iml | ||
| 31 | + *.hprof | ||
| 32 | + | ||
| 33 | + # node.js | ||
| 34 | + # | ||
| 35 | + node_modules/ | ||
| 36 | + npm-debug.log | ||
| 37 | + yarn-error.log | ||
| 38 | + | ||
| 39 | + # BUCK | ||
| 40 | + buck-out/ | ||
| 41 | + \.buckd/ | ||
| 42 | + *.keystore | ||
| 43 | + !debug.keystore | ||
| 44 | + | ||
| 45 | + # fastlane | ||
| 46 | + # | ||
| 47 | + # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
| 48 | + # screenshots whenever they are needed. | ||
| 49 | + # For more information about the recommended setup visit: | ||
| 50 | + # https://docs.fastlane.tools/best-practices/source-control/ | ||
| 51 | + | ||
| 52 | + */fastlane/report.xml | ||
| 53 | + */fastlane/Preview.html | ||
| 54 | + */fastlane/screenshots | ||
| 55 | + | ||
| 56 | + # Bundle artifact | ||
| 57 | + *.jsbundle | ||
| 58 | + | ||
| 59 | + # CocoaPods | ||
| 60 | + /ios/Pods/ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + **/*.min.js | ||
| 2 | + **/*.md | ||
| 3 | + **/*.json | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + { | ||
| 2 | + "printWidth": 120, | ||
| 3 | + "tabWidth": 2, | ||
| 4 | + "useTabs": false, | ||
| 5 | + "semi": true, | ||
| 6 | + "singleQuote": true, | ||
| 7 | + "quoteProps": "preserve", | ||
| 8 | + "trailingComma": "all", | ||
| 9 | + "bracketSpacing": true, | ||
| 10 | + "arrowParens": "avoid" | ||
| 11 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + {} | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,96 @@ | |||
| 1 | + import React, { useEffect, useState } from 'react'; | ||
| 2 | + import { ActivityIndicator, AppState, StyleSheet } from 'react-native'; | ||
| 3 | + import SendBird from 'sendbird'; | ||
| 4 | + | ||
| 5 | + import { AppContext } from './src/context'; | ||
| 6 | + import 'react-native-gesture-handler'; | ||
| 7 | + import messaging from '@react-native-firebase/messaging'; | ||
| 8 | + import { NavigationContainer } from '@react-navigation/native'; | ||
| 9 | + import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
| 10 | + | ||
| 11 | + import Lobby from './src/page/lobby'; | ||
| 12 | + import Chat from './src/page/chat'; | ||
| 13 | + import Member from './src/page/member'; | ||
| 14 | + import Invite from './src/page/invite'; | ||
| 15 | + import Profile from './src/page/profile'; | ||
| 16 | + | ||
| 17 | + import { onRemoteMessage } from './src/utils'; | ||
| 18 | + import AuthManager from './src/libs/AuthManager'; | ||
| 19 | + import NotificationManager from './src/libs/NotificationManager'; | ||
| 20 | + import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
| 21 | + | ||
| 22 | + const Stack = createNativeStackNavigator(); | ||
| 23 | + | ||
| 24 | + const appId = '9DA1B1F4-0BE6-4DA8-82C5-2E81DAB56F23'; | ||
| 25 | + const sendbird = new SendBird({ appId, localCacheEnabled: true }); | ||
| 26 | + sendbird.useAsyncStorageAsDatabase(AsyncStorage); | ||
| 27 | + | ||
| 28 | + const AppProvider = ({ children }) => { | ||
| 29 | + const [loading, setLoading] = useState(true); | ||
| 30 | + const [currentUser, setCurrentUser] = useState(null); | ||
| 31 | + | ||
| 32 | + useEffect(() => { | ||
| 33 | + AuthManager.getUserForAutoSignIn() | ||
| 34 | + .then(async user => { | ||
| 35 | + if (user) { | ||
| 36 | + // Even if an error occurs, you still need to sign-in. Because you can make a connection request offline. | ||
| 37 | + try { | ||
| 38 | + await sendbird.connect(user.userId); | ||
| 39 | + } finally { | ||
| 40 | + setCurrentUser(user); | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + }) | ||
| 44 | + .finally(() => setLoading(false)); | ||
| 45 | + | ||
| 46 | + const unsubscribes = [ | ||
| 47 | + AppState.addEventListener('change', appState => { | ||
| 48 | + if (appState === 'active') { | ||
| 49 | + sendbird.setForegroundState(); | ||
| 50 | + } else { | ||
| 51 | + sendbird.setBackgroundState(); | ||
| 52 | + } | ||
| 53 | + }).remove, | ||
| 54 | + messaging().onMessage(onRemoteMessage), | ||
| 55 | + ]; | ||
| 56 | + return () => { | ||
| 57 | + unsubscribes.forEach(fn => fn()); | ||
| 58 | + }; | ||
| 59 | + }, []); | ||
| 60 | + | ||
| 61 | + useEffect(() => { | ||
| 62 | + if (currentUser) { | ||
| 63 | + NotificationManager.setPushToken(sendbird); | ||
| 64 | + } else { | ||
| 65 | + NotificationManager.clearPushToken(sendbird); | ||
| 66 | + } | ||
| 67 | + }, [currentUser]); | ||
| 68 | + | ||
| 69 | + if (loading) return <ActivityIndicator style={StyleSheet.absoluteFill} color={'#742ddd'} size={'large'} />; | ||
| 70 | + return <AppContext.Provider value={{ sendbird, currentUser, setCurrentUser }}>{children}</AppContext.Provider>; | ||
| 71 | + }; | ||
| 72 | + | ||
| 73 | + const App = () => { | ||
| 74 | + return ( | ||
| 75 | + <AppProvider> | ||
| 76 | + <NavigationContainer> | ||
| 77 | + <Stack.Navigator> | ||
| 78 | + <Stack.Screen name="Lobby" component={Lobby} options={{ ...defaultHeaderOptions }} /> | ||
| 79 | + <Stack.Screen name="Chat" component={Chat} options={{ ...defaultHeaderOptions }} /> | ||
| 80 | + <Stack.Screen name="Member" component={Member} options={{ ...defaultHeaderOptions }} /> | ||
| 81 | + <Stack.Screen name="Invite" component={Invite} options={{ ...defaultHeaderOptions }} /> | ||
| 82 | + <Stack.Screen name="Profile" component={Profile} options={{ ...defaultHeaderOptions }} /> | ||
| 83 | + </Stack.Navigator> | ||
| 84 | + </NavigationContainer> | ||
| 85 | + </AppProvider> | ||
| 86 | + ); | ||
| 87 | + }; | ||
| 88 | + | ||
| 89 | + const defaultHeaderOptions = { | ||
| 90 | + headerStyle: { | ||
| 91 | + backgroundColor: '#742ddd', | ||
| 92 | + }, | ||
| 93 | + headerTintColor: '#fff', | ||
| 94 | + }; | ||
| 95 | + | ||
| 96 | + export default App; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,55 @@ | |||
| 1 | + # To learn about Buck see [Docs](https://buckbuild.com/). | ||
| 2 | + # To run your application with Buck: | ||
| 3 | + # - install Buck | ||
| 4 | + # - `npm start` - to start the packager | ||
| 5 | + # - `cd android` | ||
| 6 | + # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` | ||
| 7 | + # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck | ||
| 8 | + # - `buck install -r android/app` - compile, install and run application | ||
| 9 | + # | ||
| 10 | + | ||
| 11 | + load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") | ||
| 12 | + | ||
| 13 | + lib_deps = [] | ||
| 14 | + | ||
| 15 | + create_aar_targets(glob(["libs/*.aar"])) | ||
| 16 | + | ||
| 17 | + create_jar_targets(glob(["libs/*.jar"])) | ||
| 18 | + | ||
| 19 | + android_library( | ||
| 20 | + name = "all-libs", | ||
| 21 | + exported_deps = lib_deps, | ||
| 22 | + ) | ||
| 23 | + | ||
| 24 | + android_library( | ||
| 25 | + name = "app-code", | ||
| 26 | + srcs = glob([ | ||
| 27 | + "src/main/java/**/*.java", | ||
| 28 | + ]), | ||
| 29 | + deps = [ | ||
| 30 | + ":all-libs", | ||
| 31 | + ":build_config", | ||
| 32 | + ":res", | ||
| 33 | + ], | ||
| 34 | + ) | ||
| 35 | + | ||
| 36 | + android_build_config( | ||
| 37 | + name = "build_config", | ||
| 38 | + package = "com.sendbird.chat.reactnative.sample", | ||
| 39 | + ) | ||
| 40 | + | ||
| 41 | + android_resource( | ||
| 42 | + name = "res", | ||
| 43 | + package = "com.sendbird.chat.reactnative.sample", | ||
| 44 | + res = "src/main/res", | ||
| 45 | + ) | ||
| 46 | + | ||
| 47 | + android_binary( | ||
| 48 | + name = "app", | ||
| 49 | + keystore = "//android/keystores:debug", | ||
| 50 | + manifest = "src/main/AndroidManifest.xml", | ||
| 51 | + package_type = "debug", | ||
| 52 | + deps = [ | ||
| 53 | + ":app-code", | ||
| 54 | + ], | ||
| 55 | + ) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments