I am reverse-engineering a react-native bridge for a payment lib and I have no idea what this syntax mean. Is it calling some function? Ohhh is it calling some function setCallBack... which is a property defined inside the object checkout
of MercadoPagoCheckout
? And this property accepts a another function as argument and ^{ }
is some sort of anonymous function block?
I guess I just found the answer. Nevermind haha
//Set up Cancellation Callback
[checkout setCallbackCancelWithCallback:^{
[uiNavigationController setNavigationBarHidden:TRUE];
[uiNavigationController popToRootViewControllerAnimated:NO];
reject(@"PAYMENT_CANCELLED", @"Payment was cancelled by the user.", nil);
}];
Here is the full code with screenshot just for fun.
RCT_EXPORT_METHOD(startCheckoutForPayment: (NSString *) publicKey: (NSString *) preferenceId: (NSString *) color: (BOOL) enableDarkFont: (RCTPromiseResolveBlock) resolve: (RCTPromiseRejectBlock) reject) {
UINavigationController *uiNavigationController = (UINavigationController *) [UIApplication sharedApplication].delegate.window.rootViewController;
MercadoPagoCheckoutBuilder *builder = [[MercadoPagoCheckoutBuilder alloc] initWithPublicKey:publicKey preferenceId:preferenceId];
MercadoPagoCheckout *checkout = [[MercadoPagoCheckout alloc] initWithBuilder:builder];
//Set up Cancellation Callback
[checkout setCallbackCancelWithCallback:^{
[uiNavigationController setNavigationBarHidden:TRUE];
[uiNavigationController popToRootViewControllerAnimated:NO];
reject(@"PAYMENT_CANCELLED", @"Payment was cancelled by the user.", nil);
}];
...