Skip to content

Commit

Permalink
💫 Update: RNIComputable
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 28, 2023
1 parent 0872abb commit 56ae8ae
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class RNIComputableSizeEvaluator {
) -> CGSize? {
let computedSize: CGSize? = {
switch self.computableSize.mode {
case .unspecified:
return nil;

case .current:
return currentSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

public enum RNIComputableSizeMode {
case unspecified;
case current;
case stretch;
case constant(constantWidth: Double, constantHeight: Double);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,7 @@ class RNIComputableValueEvaluator {
}
};

public var jsString: String = "" {
willSet {
self.initializeJSContextIfNeeded();
self.jsContext?.setObject(
newValue,
forKeyedSubscript: JSObjectKeys.valueFunction.string
);
}
};
public var jsString: String = "";

// MARK: - Properties - Computed
// ------------------------------
Expand All @@ -95,7 +87,22 @@ class RNIComputableValueEvaluator {
self.initializeJSContextIfNeeded();

let result = jsContext.evaluateScript(
"valueFunction(getEnvObject())"
"(\(self.jsString))(\(JSObjectKeys.getEnvObject)()"
//"JSON.stringify(\(JSObjectKeys.getEnvObject)())"
);

jsContext.exceptionHandler = { context, exception in
print(
"RNIComputableValueEvaluator - computedValue"
+ " - exceptionHandler "
+ " - arg exception: \(exception.debugDescription)"
);
};

print(
"RNIComputableValueEvaluator - computedValue"
+ " - jsString: \(self.jsString)"
+ " - result: \(result)"
);

return result;
Expand Down Expand Up @@ -161,6 +168,16 @@ class RNIComputableValueEvaluator {
]
};

let getEnvObject: @convention(block)
() -> [AnyHashable: Any] = { [unowned self] in

return [
JSObjectKeys.getView: getView,
JSObjectKeys.getWindowSize: getWindowSize,
JSObjectKeys.getScreenSize: getScreenSize,
];
};

jsContext.setObject(
getView,
forKeyedSubscript: JSObjectKeys.getView.string
Expand All @@ -176,15 +193,10 @@ class RNIComputableValueEvaluator {
forKeyedSubscript: JSObjectKeys.getScreenSize.string
);

jsContext.evaluateScript("""
function \(JSObjectKeys.getEnvObject)(){
\(JSObjectKeys.getView),
getWindowSize: null,
getScreenSize: null,
\(JSObjectKeys.parentView),
};
""");
jsContext.setObject(
getEnvObject,
forKeyedSubscript: JSObjectKeys.getEnvObject.string
);
};

// MARK: - Functions - Called from JS-Side
Expand Down
33 changes: 26 additions & 7 deletions ios/src_library/React Native/RNIComputable/RNIViewMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ public final class RNIViewMetadata: RNIDictionarySynthesizable {
public let nativeID: String?;

public let parentView: RNIViewMetadata?;
public let subviews: [RNIViewMetadata];
public let subviews: [RNIViewMetadata]?;

public required init(fromView view: UIView){
public required init(
fromView view: UIView,
setParentView: Bool = true,
setSubViews: Bool = true
){
self.tag = view.tag;

self.reactTag = {
Expand All @@ -32,12 +36,27 @@ public final class RNIViewMetadata: RNIDictionarySynthesizable {
}();

self.parentView = {
guard let parentView = view.superview else { return nil };
return Self.init(fromView: parentView);
guard setParentView,
let parentView = view.superview
else { return nil };

return Self.init(
fromView: parentView,
setParentView: false,
setSubViews: false
);
}();

self.subviews = view.subviews.map {
return Self.init(fromView: $0);
};
self.subviews = {
guard setSubViews else { return nil };

return view.subviews.map {
return Self.init(
fromView: $0,
setParentView: false,
setSubViews: false
);
};
}();
};
};
2 changes: 1 addition & 1 deletion src/types/RNIComputable/RNIComputableValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export type RNIComputableValueNative = {
};

export type RNIComputableValue<FunctionArgs, FunctionReturn> = {
valueFunction: (args: FunctionArgs) => FunctionReturn;
valueFunction: string | ((args: FunctionArgs) => FunctionReturn);
extraData?: object;
};

0 comments on commit 56ae8ae

Please sign in to comment.