Skip to content

Commit

Permalink
fix(rn-072): fix generated code to be compatible with <rn.073
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas committed Nov 24, 2023
1 parent 5ae8611 commit 4b38d16
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class NativeMapViewModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public abstract class NativeMapViewModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public static final String NAME = "RNMBXMapViewModule";

public NativeMapViewModuleSpec(ReactApplicationContext reactContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class NativeRNMBXImageModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public abstract class NativeRNMBXImageModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public static final String NAME = "RNMBXImageModule";

public NativeRNMBXImageModuleSpec(ReactApplicationContext reactContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import javax.annotation.Nonnull;

public abstract class NativeRNMBXMovePointShapeAnimatorModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public abstract class NativeRNMBXMovePointShapeAnimatorModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public static final String NAME = "RNMBXMovePointShapeAnimatorModule";

public NativeRNMBXMovePointShapeAnimatorModuleSpec(ReactApplicationContext reactContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class NativeRNMBXPointAnnotationModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public abstract class NativeRNMBXPointAnnotationModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public static final String NAME = "RNMBXPointAnnotationModule";

public NativeRNMBXPointAnnotationModuleSpec(ReactApplicationContext reactContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class NativeRNMBXShapeSourceModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public abstract class NativeRNMBXShapeSourceModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public static final String NAME = "RNMBXShapeSourceModule";

public NativeRNMBXShapeSourceModuleSpec(ReactApplicationContext reactContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class NativeRNMBXViewportModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
public abstract class NativeRNMBXViewportModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public static final String NAME = "RNMBXViewportModule";

public NativeRNMBXViewportModuleSpec(ReactApplicationContext reactContext) {
Expand Down
3 changes: 3 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ buck-out/
/ios/Pods/
/ios/Podfile.lock
/vendor/bundle

# detox
artifacts
23 changes: 23 additions & 0 deletions scripts/codegen-old-arch.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ function javaOldArchDir() {
return OLD_ARCH_DIR;
}

function fixOldArchJavaForRN72Compat(dir) {
// see https://github.com/rnmapbox/maps/issues/3193
const files = fs.readdirSync(dir);
files.forEach((file) => {
const filePath = path.join(dir, file);
const fileExtension = path.extname(file);
if (fileExtension === '.java') {
let fileContent = fs.readFileSync(filePath, 'utf-8');
let newFileContent = fileContent.replace(
/extends ReactContextBaseJavaModule implements TurboModule/g,
'extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule',
);
if (fileContent !== newFileContent) {
console.log(' => fixOldArchJava applied to:', filePath);
fs.writeFileSync(filePath, newFileContent, 'utf-8');
}
} else if (fs.lstatSync(filePath).isDirectory()) {
fixOldArchJavaForRN72Compat(filePath);
}
});
}

async function generateCodegenJavaOldArch() {
exec(`rm -rf ${GENERATED_DIR} ${OLD_ARCH_DIR}`);
exec(`mkdir -p ${GENERATED_DIR}/source/codegen/`);
Expand All @@ -35,6 +57,7 @@ async function generateCodegenJavaOldArch() {
`node ${RN_DIR}/scripts/generate-specs-cli.js --platform android --schemaPath ${GENERATED_DIR}/source/codegen/schema.json --outputDir ${GENERATED_DIR}/source/codegen --libraryName rnmapbox_maps_specs --javaPackageName com.rnmapbox.rnmbx`,
);

fixOldArchJavaForRN72Compat(`${GENERATED_DIR}/source/codegen/java/`);
exec(`cp -rf ${GENERATED_DIR}/source/codegen/java/ ${OLD_ARCH_DIR}/`);
}

Expand Down

0 comments on commit 4b38d16

Please sign in to comment.