Skip to content

Commit

Permalink
chore: bump react-native version and fix badaccess on template caching
Browse files Browse the repository at this point in the history
  • Loading branch information
azimgd committed Jan 3, 2025
1 parent a792407 commit b18a07a
Show file tree
Hide file tree
Showing 15 changed files with 495 additions and 395 deletions.
1 change: 0 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ android {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"generated/java",
"generated/jni"
]
}
Expand Down
17 changes: 6 additions & 11 deletions android/src/main/java/com/shadowlist/SLContainerPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -23,11 +22,6 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext
return viewManagers;
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@Override
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
if (name.equals(SLModule.NAME)) {
Expand All @@ -41,17 +35,18 @@ public NativeModule getModule(String name, ReactApplicationContext reactContext)
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return () -> {
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();

moduleInfos.put(
SLModule.NAME,
new ReactModuleInfo(
SLModule.NAME,
SLModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
true // isTurboModule
false,
false,
false,
true
));

return moduleInfos;
};
}
Expand Down
1 change: 1 addition & 0 deletions android/src/main/java/com/shadowlist/SLModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModule;
import com.shadowlist.viewmanagers.NativeSLModuleSpec;

@ReactModule(name = SLModule.NAME)
public class SLModule extends NativeSLModuleSpec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @nolint
*/

package com.shadowlist;
package com.shadowlist.viewmanagers;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.ReactApplicationContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;

public class SLContainerManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & SLContainerManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public SLContainerManagerDelegate(U viewManager) {
super(viewManager);
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "data":
mViewManager.setData(view, value == null ? null : (String) value);
break;
case "inverted":
mViewManager.setInverted(view, value == null ? false : (boolean) value);
break;
case "horizontal":
mViewManager.setHorizontal(view, value == null ? false : (boolean) value);
break;
case "initialNumToRender":
mViewManager.setInitialNumToRender(view, value == null ? 0 : ((Double) value).intValue());
break;
case "initialScrollIndex":
mViewManager.setInitialScrollIndex(view, value == null ? 0 : ((Double) value).intValue());
break;
default:
super.setProperty(view, propName, value);
}
}

@Override
public void receiveCommand(T view, String commandName, @Nullable ReadableArray args) {
switch (commandName) {
case "scrollToIndex":
mViewManager.scrollToIndex(view, args.getInt(0), args.getBoolean(1));
break;
case "scrollToOffset":
mViewManager.scrollToOffset(view, args.getInt(0), args.getBoolean(1));
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;

public interface SLContainerManagerInterface<T extends View> {
void setData(T view, @Nullable String value);
void setInverted(T view, boolean value);
void setHorizontal(T view, boolean value);
void setInitialNumToRender(T view, int value);
void setInitialScrollIndex(T view, int value);
void scrollToIndex(T view, int index, boolean animated);
void scrollToOffset(T view, int offset, boolean animated);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;

public class SLElementManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & SLElementManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public SLElementManagerDelegate(U viewManager) {
super(viewManager);
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "uniqueId":
mViewManager.setUniqueId(view, value == null ? null : (String) value);
break;
default:
super.setProperty(view, propName, value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;

public interface SLElementManagerInterface<T extends View> {
void setUniqueId(T view, @Nullable String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,7 @@ void SLContainerShadowNode::layout(LayoutContext layoutContext) {
};

auto transformTemplateComponent = [&](std::string elementDataUniqueKey, int templateDataIndex) -> ComponentRegistryItem {
auto elementShadowNodeComponentRegistryIt = elementShadowNodeComponentRegistry.find(elementDataUniqueKey);
if (elementShadowNodeComponentRegistryIt == elementShadowNodeComponentRegistry.end()) {
const nlohmann::json& elementData = {};
elementShadowNodeComponentRegistry[elementDataUniqueKey] = SLTemplate::cloneShadowNodeTree(elementData, elementShadowNodeTemplateRegistry[elementDataUniqueKey].back());
} else {
elementShadowNodeComponentRegistry[elementDataUniqueKey] = elementShadowNodeComponentRegistry[elementDataUniqueKey]->clone({});
}

auto elementShadowNodeLayoutable = std::static_pointer_cast<YogaLayoutableShadowNode>(elementShadowNodeComponentRegistry[elementDataUniqueKey]);
elementShadowNodeComponentRegistry[elementDataUniqueKey] = elementShadowNodeTemplateRegistry[elementDataUniqueKey].back()->clone({});

// Prevent re-measuring if the height is already defined, as layouting is expensive
auto elementSize = layoutElement(layoutContext, elementShadowNodeComponentRegistry[elementDataUniqueKey]);
Expand Down
Loading

0 comments on commit b18a07a

Please sign in to comment.