Skip to content

Instantly share code, notes, and snippets.

View troZee's full-sized avatar

troZee

View GitHub Profile
@troZee
troZee / gist:a611537cb41e7ccec47b35ddb5faaaea
Created May 19, 2023 09:20
Calling a JS method from a native module using JSI in the React Native
// JS
BatchedBridge.registerCallableModule('JavaScriptVisibleToJava', {
alert: () => {
console.log('JavaScriptVisibleToJava');
},
});
//iOS
[self.bridge enqueueJSCall:@"JavaScriptVisibleToJava" method:@"alert" args:@[] completion:NULL];
@troZee
troZee / checkDepLastPublish.js
Created December 15, 2022 15:25
Check npm last publish date for each dependency inside a package.json file
const fs = require('fs');
const { exec } = require('child_process');
function execute(command, callback) {
exec(command, function (error, stdout, stderr) {
if (stderr || error) {
// console.log(`🚀🚀🚀🚀🚀🚀🚀🚀 ${stderr} ${error}`);
} else {
callback(stdout);
}
@troZee
troZee / changelog.md
Last active June 29, 2022 09:51
How to generate changelog from git

Get diff on current branch

Command:

git --no-pager show -s --date=local --pretty=format:"- %h (%ae) %s%n"

Output:

- dcd509e (user@github.com) fix(ios): commit message 
@troZee
troZee / codegen.json
Created March 17, 2022 15:46
This is how callExpression looks like
{
"type": "TypeCastExpression",
"loc": {
"source": null,
"start": {
"line": 57,
"column": 41
},
"end": {
"line": 64,
@troZee
troZee / priceRegex.js
Created January 1, 2021 13:10
Price regex for positive and negative numbers
const regex = /(^\-?0[\,\.][0-9]{1,}$)|(^\-?[1-9][0-9]{1,}$)|(^[0-9]$)|(^\-?[1-9][0-9]{0,}[\,\.][0-9]{1,}$)|(^\-?[1-9]$)/gm;
const str = `01
001
033
0000033
00000.2
00000000000000
01010101010
0000.0
aaa
@troZee
troZee / regex.js
Created January 1, 2021 13:06
regex for only positive price
const regex = /(^0[\,\.][0-9]{1,}$)|(^[1-9][0-9]{1,}$)|(^[0-9]$)|(^[1-9][0-9]{0,}[\,\.][0-9]{1,}$)/gm;
const str = `01
001
033
0000033
00000.2
00000000000000
01010101010
0000.0
aaa
@troZee
troZee / UIPageControl.m
Created November 2, 2019 22:10
Add UIPageControl dynamically
UIPageControl *pageIndicatorView = [[UIPageControl alloc] init];
pageIndicatorView.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *bottomConstraint = [pageIndicatorView.bottomAnchor constraintEqualToAnchor: self.view.bottomAnchor constant:0];
NSLayoutConstraint *leadingConstraint = [pageIndicatorView.leadingAnchor constraintEqualToAnchor: self.view.leadingAnchor constant:0];
NSLayoutConstraint *trailingConstraint = [pageIndicatorView.trailingAnchor constraintEqualToAnchor: self.view.trailingAnchor constant:0];
[self.view addConstraints:@[bottomConstraint,leadingConstraint,trailingConstraint]];
[self.view layoutIfNeeded];
#import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>
#import <React/RCTLog.h>
RCT_EXPORT_METHOD(goToPreviousPage:(nonnull NSNumber*) reactTag) {
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
NativeView *view = viewRegistry[reactTag];
if (!view || ![view isKindOfClass:[NativeView class]]) {
RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
return;
}
class MyNativeView extends React.Component<Props> {
goToNextPage = () => {
UIManager.dispatchViewManagerCommand(
ReactNative.findNodeHandle(this),
UIManager.getViewManagerConfig('RNCMyNativeView').Commands.goToNextPage,
[]
);
};
goToPreviousPage = () => {
class MyNativeView extends React.Component<Props> {
goToNextPage = () => {
NativeModules.RNCMyNativeView.goToNextPage();
};
goToPreviousPage = () => {
NativeModules.RNCMyNativeView.goToPreviousPage();
};
render() {