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
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class TransactReactNativeModule(reactContext: ReactApplicationContext) :
id: String,
environment: ReadableMap,
wrapperVersion: String,
headless: Boolean?,
promise: Promise,
) {
val context = reactApplicationContext.currentActivity as Context
Expand All @@ -135,7 +136,8 @@ class TransactReactNativeModule(reactContext: ReactApplicationContext) :
val config = ActionConfig(
id = id,
environment = Config.Environment.CUSTOM,
environmentURL = environmentURL
environmentURL = environmentURL,
headless = headless,
)
config.platform = Config.Platform.suffixed("react-$wrapperVersion")

Expand Down
18 changes: 18 additions & 0 deletions example/screens/PresentActionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const PresentActionScreen: React.FC<Props> = () => {
const [presentationStyleIOS, setPresentationStyleIOS] =
useState<PresentationStyleIOS>(PresentationStyles.formSheet);
const [debugEnabled, setDebugEnabled] = useState(false);
const [headless, setHeadless] = useState(false);

const environmentOptions = [
{ key: 'sandbox' as EnvironmentOption, label: 'Sandbox' },
Expand Down Expand Up @@ -88,6 +89,7 @@ const PresentActionScreen: React.FC<Props> = () => {
environment: getEnvironment(),
presentationStyleIOS,
setDebug: debugEnabled,
headless,
onLaunch: () => {
console.log('Action launched');
setIsLoading(false);
Expand Down Expand Up @@ -191,6 +193,22 @@ const PresentActionScreen: React.FC<Props> = () => {
</View>
</View>

<View style={styles.section}>
<Text style={styles.sectionTitle}>Headless</Text>
<View style={styles.switchGroup}>
<View style={styles.switchContainer}>
<Text style={styles.switchLabel}>Off</Text>
<Switch
value={headless}
onValueChange={setHeadless}
trackColor={{ false: '#d1d5db', true: '#3b82f6' }}
thumbColor="#fff"
/>
<Text style={styles.switchLabel}>On</Text>
</View>
</View>
</View>

<View style={styles.section}>
<Text style={styles.sectionTitle}>How it works</Text>
<View style={styles.infoCard}>
Expand Down
1 change: 1 addition & 0 deletions ios/TransactReactNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface RCT_EXTERN_MODULE(TransactReactNative, RCTEventEmitter)
environment:(NSDictionary *)environment
presentationStyle:(nullable NSString *)presentationStyle
setDebug:(nullable NSNumber *)setDebug
headless:(nullable NSNumber *)headless
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

Expand Down
6 changes: 4 additions & 2 deletions ios/TransactReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ class TransactReactNative: RCTEventEmitter {
}
}

@objc(presentAction:environment:presentationStyle:setDebug:withResolver:withRejecter:)
func presentAction(id: String, environment: [String: Any], presentationStyle: String?, setDebug: NSNumber?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
@objc(presentAction:environment:presentationStyle:setDebug:headless:withResolver:withRejecter:)
func presentAction(id: String, environment: [String: Any], presentationStyle: String?, setDebug: NSNumber?, headless: NSNumber?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
let debugEnabled = setDebug?.boolValue ?? false
let headlessEnabled = headless?.boolValue ?? false

Task { @MainActor in
await Atomic.setDebug(isEnabled: debugEnabled, forwardLogs: { logMessage in
Expand All @@ -152,6 +153,7 @@ class TransactReactNative: RCTEventEmitter {
id: id,
environment: parsedEnvironment,
presentationStyle: parsedPresentationStyle,
headless: headlessEnabled,
onLaunch: {
self.sendEvent(withName: "onLaunch", body: [])
},
Expand Down
9 changes: 8 additions & 1 deletion src/android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const AtomicAndroid = {
id,
environment,
wrapperVersion,
headless,
onLaunch,
onFinish,
onClose,
Expand All @@ -62,6 +63,7 @@ export const AtomicAndroid = {
id: String;
environment?: CONSTANTS.TransactEnvironment;
wrapperVersion: string;
headless?: boolean;
onLaunch?: Function;
onFinish?: Function;
onClose?: Function;
Expand All @@ -74,6 +76,11 @@ export const AtomicAndroid = {
_addEventListener('onTaskStatusUpdate', onTaskStatusUpdate);
_addEventListener('onAuthStatusUpdate', onAuthStatusUpdate);

TransactReactNative.presentAction(id, environment, wrapperVersion);
TransactReactNative.presentAction(
id,
environment,
wrapperVersion,
headless
);
},
};
3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const Atomic = {
id,
environment,
presentationStyleIOS,
headless,
onLaunch,
onFinish,
onClose,
Expand All @@ -165,6 +166,7 @@ export const Atomic = {
id: String;
environment?: CONSTANTS.TransactEnvironment;
presentationStyleIOS?: PresentationStyleIOS;
headless?: boolean;
onLaunch?: Function;
onFinish?: Function;
onClose?: Function;
Expand All @@ -178,6 +180,7 @@ export const Atomic = {
environment: environment || CONSTANTS.Environment.production,
wrapperVersion,
presentationStyleIOS,
headless,
onLaunch,
onFinish,
onClose,
Expand Down
5 changes: 4 additions & 1 deletion src/ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const AtomicIOS = {
id,
environment,
presentationStyleIOS,
headless,
onLaunch,
onFinish,
onClose,
Expand All @@ -129,6 +130,7 @@ export const AtomicIOS = {
// for parity with Android callers but not forwarded to native.
wrapperVersion?: string;
presentationStyleIOS?: CONSTANTS.PresentationStyleIOS;
headless?: boolean;
onLaunch?: Function;
onFinish?: Function;
onClose?: Function;
Expand Down Expand Up @@ -180,7 +182,8 @@ export const AtomicIOS = {
id,
environment,
presentationStyleIOS,
setDebug
setDebug,
headless
).then((event: any) => {
if (event.finished && onFinish) {
removeListeners();
Expand Down
Loading