Skip to content

Commit 2828a34

Browse files
authored
chore: imessageclone maintenance, upgrading dependencies, added alert if no env variables found (#51)
* chore: imessageclone maintenance, upgrading dependencies, added alert if no env variables found * fix: broken camera usage due to missing permissions in info.plist * fix: creating new channel and send message issue using overrideOwnCapabilities
1 parent 985ebcb commit 2828a34

File tree

19 files changed

+753
-721
lines changed

19 files changed

+753
-721
lines changed

projects/iMessageClone/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ build/
3030
local.properties
3131
*.iml
3232
*.hprof
33+
.cxx/
3334

3435
# node.js
3536
#

projects/iMessageClone/App.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {Channel as ChannelType} from 'stream-chat';
1515
import {useStreamChatTheme} from './useStreamChatTheme';
1616
import {chatClient, user, userToken} from './src/client';
1717
import {GestureHandlerRootView} from 'react-native-gesture-handler';
18+
import {Alert} from 'react-native';
1819

1920
type State = {
2021
channel?: ChannelType;
@@ -32,6 +33,12 @@ const App = () => {
3233

3334
useEffect(() => {
3435
const setupClient = async () => {
36+
if (!user.id || !userToken) {
37+
Alert.alert(
38+
'Please set API_KEY, USER_ID and USER_TOKEN in .env file as mentioned in README file and restart the project',
39+
);
40+
return;
41+
}
3542
await chatClient.connectUser(user, userToken);
3643
setClientReady(true);
3744
};

projects/iMessageClone/android/app/build.gradle

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
4+
import org.apache.tools.ant.taskdefs.condition.Os
45

56
/**
67
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
@@ -143,22 +144,14 @@ android {
143144
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
144145

145146
if (isNewArchitectureEnabled()) {
146-
// We configure the NDK build only if you decide to opt-in for the New Architecture.
147+
// We configure the CMake build only if you decide to opt-in for the New Architecture.
147148
externalNativeBuild {
148-
ndkBuild {
149-
arguments "APP_PLATFORM=android-21",
150-
"APP_STL=c++_shared",
151-
"NDK_TOOLCHAIN_VERSION=clang",
152-
"GENERATED_SRC_DIR=$buildDir/generated/source",
153-
"PROJECT_BUILD_DIR=$buildDir",
154-
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
155-
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
156-
"NODE_MODULES_DIR=$rootDir/../node_modules"
157-
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
158-
cppFlags "-std=c++17"
159-
// Make sure this target name is the same you specify inside the
160-
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
161-
targets "imessageclone_appmodules"
149+
cmake {
150+
arguments "-DPROJECT_BUILD_DIR=$buildDir",
151+
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
152+
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
153+
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
154+
"-DANDROID_STL=c++_shared"
162155
}
163156
}
164157
if (!enableSeparateBuildPerCPUArchitecture) {
@@ -172,8 +165,8 @@ android {
172165
if (isNewArchitectureEnabled()) {
173166
// We configure the NDK build only if you decide to opt-in for the New Architecture.
174167
externalNativeBuild {
175-
ndkBuild {
176-
path "$projectDir/src/main/jni/Android.mk"
168+
cmake {
169+
path "$projectDir/src/main/jni/CMakeLists.txt"
177170
}
178171
}
179172
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
@@ -195,15 +188,15 @@ android {
195188
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
196189

197190
// Due to a bug inside AGP, we have to explicitly set a dependency
198-
// between configureNdkBuild* tasks and the preBuild tasks.
191+
// between configureCMakeDebug* tasks and the preBuild tasks.
199192
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
200-
configureNdkBuildRelease.dependsOn(preReleaseBuild)
201-
configureNdkBuildDebug.dependsOn(preDebugBuild)
193+
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
194+
configureCMakeDebug.dependsOn(preDebugBuild)
202195
reactNativeArchitectures().each { architecture ->
203-
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
196+
tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
204197
dependsOn("preDebugBuild")
205198
}
206-
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
199+
tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
207200
dependsOn("preReleaseBuild")
208201
}
209202
}

projects/iMessageClone/android/app/src/main/jni/Android.mk

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
# Define the library name here.
3+
project(rndiffapp_appmodules)
4+
# This file includes all the necessary to let you build your application with the New Architecture.
5+
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)

projects/iMessageClone/android/app/src/main/jni/MainApplicationModuleProvider.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include "MainApplicationModuleProvider.h"
22
#include <rncore.h>
3+
#include <rncli.h>
4+
35
namespace facebook
46
{
57
namespace react
68
{
79
std::shared_ptr<TurboModule> MainApplicationModuleProvider(
8-
const std::string moduleName,
10+
const std::string &moduleName,
911
const JavaTurboModule::InitParams &params)
1012
{
1113
// Here you can provide your own module provider for TurboModules coming from
@@ -17,7 +19,15 @@ namespace facebook
1719
// return module;
1820
// }
1921
// return rncore_ModuleProvider(moduleName, params);
22+
23+
// Module providers autolinked by RN CLI
24+
auto rncli_module = rncli_ModuleProvider(moduleName, params);
25+
if (rncli_module != nullptr)
26+
{
27+
return rncli_module;
28+
}
29+
2030
return rncore_ModuleProvider(moduleName, params);
2131
}
2232
} // namespace react
23-
} // namespace facebook
33+
} // namespace facebook

projects/iMessageClone/android/app/src/main/jni/MainApplicationModuleProvider.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace facebook
99
namespace react
1010
{
1111
std::shared_ptr<TurboModule> MainApplicationModuleProvider(
12-
const std::string moduleName,
12+
const std::string &moduleName,
1313
const JavaTurboModule::InitParams &params);
1414
} // namespace react
15-
} // namespace facebook
15+
} // namespace facebook

projects/iMessageClone/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ namespace facebook
2222
}
2323
std::shared_ptr<TurboModule>
2424
MainApplicationTurboModuleManagerDelegate::getTurboModule(
25-
const std::string name,
26-
const std::shared_ptr<CallInvoker> jsInvoker)
25+
const std::string &name,
26+
const std::shared_ptr<CallInvoker> &jsInvoker)
2727
{
2828
// Not implemented yet: provide pure-C++ NativeModules here.
2929
return nullptr;
3030
}
3131
std::shared_ptr<TurboModule>
3232
MainApplicationTurboModuleManagerDelegate::getTurboModule(
33-
const std::string name,
33+
const std::string &name,
3434
const JavaTurboModule::InitParams &params)
3535
{
3636
return MainApplicationModuleProvider(name, params);
3737
}
3838
bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule(
39-
std::string name)
39+
const std::string &name)
4040
{
4141
return getTurboModule(name, nullptr) != nullptr ||
4242
getTurboModule(name, {.moduleName = name}) != nullptr;

projects/iMessageClone/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ namespace facebook
2020
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>);
2121
static void registerNatives();
2222
std::shared_ptr<TurboModule> getTurboModule(
23-
const std::string name,
23+
const std::string &name,
2424
const std::shared_ptr<CallInvoker> jsInvoker) override;
2525
std::shared_ptr<TurboModule> getTurboModule(
26-
const std::string name,
26+
const std::string &name,
2727
const JavaTurboModule::InitParams &params) override;
2828
/**
2929
* Test-only method. Allows user to verify whether a TurboModule can be
3030
* created by instances of this class.
3131
*/
32-
bool canCreateTurboModule(std::string name);
32+
bool canCreateTurboModule(const std::string &name);
3333
};
3434
} // namespace react
3535
} // namespace facebook

projects/iMessageClone/android/app/src/main/jni/MainComponentsRegistry.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <fbjni/fbjni.h>
44
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
55
#include <react/renderer/components/rncore/ComponentDescriptors.h>
6+
#include <rncli.h>
7+
68
namespace facebook
79
{
810
namespace react
@@ -12,6 +14,10 @@ namespace facebook
1214
MainComponentsRegistry::sharedProviderRegistry()
1315
{
1416
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
17+
18+
// Autolinked providers registered by RN CLI
19+
rncli_registerProviders(providerRegistry);
20+
1521
// Custom Fabric Components go here. You can register custom
1622
// components coming from your App or from 3rd party libraries here.
1723
//

0 commit comments

Comments
 (0)