Skip to content
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
49 changes: 49 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.android.Version
import in.juspay.payments.core.ClientConfig
import groovy.json.JsonSlurper

buildscript {
repositories {
Expand All @@ -14,6 +15,53 @@ buildscript {
}
}

def getRNVersion() {
def rootPackageFile = new File(rootDir, "../package.json")
if (rootPackageFile.exists()) {
try {
def json = new JsonSlurper().parse(rootPackageFile)
def version = json.dependencies["react-native"] ?: json.devDependencies["react-native"]
if (version) {
return version
}
} catch (Exception e) {
// Ignore parsing errors and continue
}
}

def searchPaths = [
'../react-native/package.json',
'../../react-native/package.json',
'../../../react-native/package.json',
'node_modules/react-native/package.json',
'../node_modules/react-native/package.json',
'../../node_modules/react-native/package.json'
]

for (path in searchPaths) {
def packageFile = new File(project.projectDir, path).getCanonicalFile()
if (packageFile.exists()) {
try {
def json = new JsonSlurper().parse(packageFile)
def version = json.version
if (version) {
if (version == '*' || version.contains('*')) {
return "0.80.0" // Default for wildcard versions
}
return version
}
} catch (Exception e) {
// Ignore parsing errors and continue
}
}
}
return "0.77.0"
}


def rnVersion = getRNVersion()
println "Found react native version as ${rnVersion}"

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}
Expand Down Expand Up @@ -49,6 +97,7 @@ android {
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
buildConfigField "String", "REACT_NATIVE_VERSION", "\"${rnVersion}\""
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import androidx.fragment.app.FragmentActivity;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactHost;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactRootView;
import com.facebook.react.bridge.ActivityEventListener;
Expand Down Expand Up @@ -89,6 +90,8 @@ public class HyperSdkReactModule extends ReactContextBaseJavaModule implements A

private boolean wasProcessWithActivity = false;

private boolean useNewApprochForMerchantView = false;

private Set<String> registeredComponents = new HashSet<>();

@NonNull
Expand All @@ -97,6 +100,7 @@ public class HyperSdkReactModule extends ReactContextBaseJavaModule implements A
HyperSdkReactModule(ReactApplicationContext reactContext) {
super(reactContext);
this.context = reactContext;
useNewApprochForMerchantView = setUseNewApprochForMerchantView();
reactContext.addActivityEventListener(this);
}

Expand Down Expand Up @@ -318,20 +322,56 @@ public View createReactSurfaceView(String viewName) {
}

private View createMerchantView(String viewName) {
if (newArchEnabled) {
return createReactSurfaceView(viewName);
} else {

if (!useNewApprochForMerchantView) {
if (reactInstanceManager == null) {
Application app = activity.getApplication();
if (app instanceof ReactApplication) {
reactInstanceManager = ((ReactApplication) app).getReactNativeHost().getReactInstanceManager();
}
}
if (newArchEnabled) {
return createReactSurfaceView(viewName);
}
if (reactInstanceManager == null) {
return null;
}
ReactRootView reactRootView = new ReactRootView(activity);
reactRootView.startReactApplication(reactInstanceManager, viewName);
return reactRootView;
}
try {
ReactHost reactHost = ((ReactApplication) activity.getApplication()).getReactHost();
if (reactHost != null) {
Object surface = reactHost.createSurface(
activity,
viewName,
null
);
surface.getClass().getMethod("start").invoke(surface);

return (View) surface.getClass().getMethod("getView").invoke(surface);
}
return null;
} catch (Exception e) {
SdkTracker.trackAndLogBootException(
NAME,
LogConstants.CATEGORY_LIFECYCLE,
LogConstants.SUBCATEGORY_HYPER_SDK,
LogConstants.SDK_TRACKER_LABEL,
"Exception in createMerchantView",
e
);
return null;
}
}


@Nullable
@Override
public View getMerchantView(ViewGroup viewGroup, MerchantViewType merchantViewType) {
Activity activity = (Activity) getCurrentActivity();
if (reactInstanceManager == null || activity == null) {
if (activity == null) {
return super.getMerchantView(viewGroup, merchantViewType);
} else {
View merchantView = null;
Expand Down Expand Up @@ -370,6 +410,17 @@ public View getMerchantView(ViewGroup viewGroup, MerchantViewType merchantViewTy
}
}

private Boolean setUseNewApprochForMerchantView() {
String version = BuildConfig.REACT_NATIVE_VERSION;
String[] parts = version.split("\\.");
if (parts.length > 1) {
int major = Integer.parseInt(parts[0]);
int minor = Integer.parseInt(parts[1]);
return major > 0 || (major == 0 && minor >= 82);
}
return false;
}

private void createHyperService(@Nullable String tenantId, @Nullable String clientId) {
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
if (activity == null) {
Expand All @@ -384,7 +435,6 @@ private void createHyperService(@Nullable String tenantId, @Nullable String clie
Application app = activity.getApplication();
if (app instanceof ReactApplication) {
this.app = ((ReactApplication) app);
reactInstanceManager = ((ReactApplication) app).getReactNativeHost().getReactInstanceManager();
}
if (tenantId != null && clientId != null) {
hyperServices = new HyperServices(activity, tenantId, clientId);
Expand Down
16 changes: 12 additions & 4 deletions hyper-sdk-react.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))

rn_minor_version = 0
rn_major_version = 0
[
'../react-native/package.json',
'../../react-native/package.json',
Expand All @@ -16,8 +17,11 @@ rn_minor_version = 0
version = package1 ['version']
if version == '*' || version.include?('*')
rn_minor_version = 80
rn_major_version = 0
else
rn_minor_version = version.split('.')[1].to_i
version_parts = version.split('.')
rn_major_version = version_parts[0].to_i
rn_minor_version = version_parts[1].to_i
end
break
rescue => e
Expand All @@ -39,8 +43,11 @@ if rn_minor_version == 0
version = package1 ['version']
if version == '*' || version.include?('*')
rn_minor_version = 80
rn_major_version = 0
else
rn_minor_version = version.split('.')[1].to_i
version_parts = version.split('.')
rn_major_version = version_parts[0].to_i
rn_minor_version = version_parts[1].to_i
end
break
rescue => e
Expand All @@ -52,8 +59,9 @@ end
# Fallback if still not found
if rn_minor_version == 0
rn_minor_version = 77
rn_major_version = 0
end
puts ("Found react native minor version as #{rn_minor_version}").yellow
puts ("Found react native minor version as #{rn_major_version}.#{rn_minor_version}").yellow

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Expand All @@ -79,7 +87,7 @@ puts ("HyperSDK Version: #{hyper_sdk_version}")
source_files_array = ["ios/**/*.{h,m,mm,swift}"]
exclude_files = []

if rn_minor_version >= 78
if rn_minor_version >= 78 || (rn_major_version > 0)
source_files_array << "ios/latest/**/*.{h,m,mm,swift}"
exclude_files << "ios/rn77/**/*"
else
Expand Down
Loading