Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context generics, types name refactor #1496

Merged
merged 38 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1436681
add fail sdk test
Marius456 Mar 13, 2024
aeaecea
Bump follow-redirects from 1.15.5 to 1.15.6
dependabot[bot] Mar 17, 2024
ad634a6
add success test
Marius456 Mar 19, 2024
0bb4f5b
fix android styles, colors
ElenaDiachenko Mar 19, 2024
7a57a5c
fix all android based platforms
ElenaDiachenko Mar 19, 2024
51ac1c4
update tests
Marius456 Mar 19, 2024
223f6b0
add variations of test
Marius456 Mar 19, 2024
aab7c89
update test
Marius456 Mar 20, 2024
9a6c9cd
fix target not found test
Marius456 Mar 20, 2024
b64c92b
add isSystem to context
Marius456 Mar 20, 2024
444d8e3
Merge branch 'release/1.0' into chore/UT_sdk_webos_device_manager
Marius456 Mar 20, 2024
33bfd3d
small fix
Marius456 Mar 20, 2024
930c080
fix UT due to migration to getContext DI
Marius456 Mar 20, 2024
bf3eb39
Bump webpack-dev-middleware from 5.3.3 to 5.3.4
dependabot[bot] Mar 23, 2024
e43aad4
add styles_xml generating
ElenaDiachenko Mar 23, 2024
b1ef487
fix _parseNode func, add strings_xml and colors_xml generating
ElenaDiachenko Mar 24, 2024
98d915d
fix schema
ElenaDiachenko Mar 24, 2024
b6fe66c
fix all strings_xml and colors_xml for android based platforms
ElenaDiachenko Mar 25, 2024
4dc38f2
clean code
ElenaDiachenko Mar 25, 2024
b213320
fix android e2e
Marius456 Mar 26, 2024
8866e8d
refactor getConfigProp to be extendable trough context generics
pavjacko Apr 7, 2024
c59b806
Merge branch 'release/1.0' of github.com:flexn-io/renative into relea…
pavjacko Apr 7, 2024
5e21159
migrate to new contextProps
pavjacko Apr 7, 2024
b7bcd58
Merge branch 'fix/android_resources' into chore/config_generics
pavjacko Apr 7, 2024
b469347
update type names, pathNames, merge fixes
pavjacko Apr 7, 2024
2dff97e
Merge branch 'chore/UT_sdk_webos_device_manager' into chore/config_ge…
pavjacko Apr 7, 2024
de979bc
cleanup core mocks, fix UTs
pavjacko Apr 7, 2024
7e0ba5d
cleanup test structure
pavjacko Apr 7, 2024
09a34be
Merge pull request #1480 from flexn-io/dependabot/npm_and_yarn/webpac…
pavjacko Apr 7, 2024
a09c627
Merge pull request #1472 from flexn-io/dependabot/npm_and_yarn/follow…
pavjacko Apr 7, 2024
9551175
update buildConfig merges
pavjacko Apr 8, 2024
4a1da61
fix private configs
pavjacko Apr 8, 2024
6d0828e
fix asset copy, cleanup resources
pavjacko Apr 8, 2024
38c9059
add multi-folder resources support spec
pavjacko Apr 8, 2024
51d3df7
Merge branch 'chore/config_generics' of github.com:flexn-io/renative …
pavjacko Apr 8, 2024
99365b5
update, fix schema
pavjacko Apr 8, 2024
7bb4296
cleanup
pavjacko Apr 8, 2024
70c4da6
fix manifest merging
pavjacko Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add styles_xml generating
  • Loading branch information
ElenaDiachenko committed Mar 23, 2024
commit e43aad46a61843df161d46285f07ccb5b1d9ab53
20 changes: 14 additions & 6 deletions packages/app-harness/renative.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@
"android": {
"templateAndroid": {
"styles_xml": {
"values": {
"app_children": [{ "tag": "item", "name": "android:windowIsTranslucent", "child_value": true }]
},
"values_v28": {
"app_children": [{ "tag": "item", "name": "android:windowIsTranslucent", "child_value": true }]
}
"tag": "resources",
"children": [
{
"tag": "style",
"name": "AppTheme",
"children": [
{
"tag": "item",
"name": "android:windowIsTranslucent",
"value": "true"
}
]
}
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const TemplateAndroidFragment = {
settings_gradle: z.optional(z.object({})),
gradle_wrapper_properties: z.optional(z.object({})),
SplashActivity_java: z.optional(z.object({})),
colors_xml: z.optional(z.object({})),
proguard_rules_pro: z.optional(z.object({})),
})
),
Expand Down
93 changes: 28 additions & 65 deletions packages/core/src/schema/platforms/fragments/templateAndroidBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const ManifestChildBase = z.object({
// 'tools:targetApi': 28,
});

const ResourcesChildBase = z.object({
tag: z.string(),
name: z.string(),
parent: z.optional(z.string()),
});

// type ManifestFeature = {
// tag: string;
// 'android:name': string;
Expand All @@ -61,6 +67,13 @@ const ManifestChildWithChildren: z.ZodType<_ManifestChildType> = ManifestChildBa
children: z.lazy(() => ManifestChildWithChildren.array()),
});

export type _ResourcesChildType = z.infer<typeof ResourcesChildBase> & {
children?: _ResourcesChildType[];
};

const ResourcesChildWithChildren: z.ZodType<_ResourcesChildType> = ResourcesChildBase.extend({
children: z.lazy(() => ResourcesChildWithChildren.array()),
});
const AndroidManifest = ManifestChildBase.extend({
package: z.string().optional(),
children: z.array(ManifestChildWithChildren),
Expand All @@ -69,6 +82,14 @@ Injects / Overrides values in AndroidManifest.xml file of generated android base
> IMPORTANT: always ensure that your object contains \`tag\` and \`android:name\` to target correct tag to merge into
`);

const Resources = ResourcesChildBase.extend({
// package: z.string().optional(),
children: z.array(ResourcesChildWithChildren),
}).describe(`Allows you to directly manipulate \`res/values files\` via json override mechanism
Injects / Overrides values in res/values files of generated android based project
> IMPORTANT: always ensure that your object contains \`tag\` and \`name\` to target correct tag to merge into
`);

// const Gradle = z.object({

// });
Expand All @@ -78,71 +99,10 @@ export const TemplateAndroidBaseFragment = {
build_gradle: z.optional(BuildGradle),
app_build_gradle: z.optional(AppBuildGradle),
AndroidManifest_xml: z.optional(AndroidManifest),
styles_xml: z.optional(
z.object({
values: z
.optional(
z.object({
app_children: z.optional(
z.array(
z.object({
tag: z.string(),
name: z.string(),
child_value: z.string(),
})
)
),
splash_children: z.optional(
z.array(
z.object({
tag: z.string(),
name: z.string(),
child_value: z.string(),
})
)
),
})
)
.describe('Allows you to add styles to values/styles.xml'),
values_v28: z
.optional(
z.object({
app_children: z.optional(
z.array(
z.object({
tag: z.string(),
name: z.string(),
child_value: z.string(),
})
)
),
splash_children: z.optional(
z.array(
z.object({
tag: z.string(),
name: z.string(),
child_value: z.string(),
})
)
),
})
)
.describe('Allows you to add styles to values-v28/styles.xml'),
})
),
strings_xml: z.optional(
z.object({
children: z.optional(
z.array(
z.object({
tag: z.string(),
name: z.string(),
child_value: z.string(),
})
)
),
})
),
styles_xml: z.optional(Resources),
strings_xml: z.optional(Resources),
colors_xml: z.optional(Resources),

MainActivity_kt: z.optional(
z.object({
onCreate: z
Expand Down Expand Up @@ -179,3 +139,6 @@ export const TemplateAndroidBaseFragment = {
export type _ManifestChildWithChildrenType = z.infer<typeof ManifestChildWithChildren>;

export type _AndroidManifestType = z.infer<typeof AndroidManifest>;

export type _ResourcesChildWithChildrenType = z.infer<typeof ResourcesChildWithChildren>;
export type _AndroidResourcesType = z.infer<typeof Resources>;
11 changes: 10 additions & 1 deletion packages/core/src/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import type { _MergedPlatformObjectType } from './platforms';
import type { _RootAppBaseSchemalType } from './configFiles/app';

import type { _RootProjectBaseSchemaType } from './configFiles/project';
import type { _AndroidManifestType, _ManifestChildWithChildrenType } from './platforms/fragments/templateAndroidBase';
import type {
_AndroidManifestType,
_AndroidResourcesType,
_ManifestChildWithChildrenType,
_ResourcesChildWithChildrenType,
} from './platforms/fragments/templateAndroidBase';
import type { _MergedPlatformPrivateObjectType } from './configFiles/private';
import type { ConfigFileBuildConfig } from './configFiles/buildConfig';

Expand Down Expand Up @@ -42,6 +47,10 @@ export type AndroidManifestNode = _ManifestChildWithChildrenType;

export type AndroidManifest = _AndroidManifestType;

export type AndroidResources = _AndroidResourcesType;

export type AndroidResourcesNode = _ResourcesChildWithChildrenType;

// export type ManifestNode = _ManifestChildType;

// export const test = (test: _ConfigRootMerged) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="android:windowBackground">@color/bg</item>
{{VALUES_STYLES_APP}}
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/bg</item>
{{VALUES_STYLES_SPLASH}}
</style>
</resources>

<!--
Generate by ReNative (https://renative.org)
BASE: packages/sdk-android/supportFiles/styles_xml.json
-->

{{PLUGIN_STYLES_XML_FILE}}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="android:windowBackground">@color/bg</item>
{{VALUES_STYLES_APP}}
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/bg</item>
{{VALUES_STYLES_SPLASH}}
</style>
</resources>

<!--
Generate by ReNative (https://renative.org)
BASE: packages/sdk-android/supportFiles/styles_xml.json
-->

{{PLUGIN_STYLES_XML_FILE}}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="android:windowBackground">@color/bg</item>
{{VALUES_STYLES_APP}}
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/bg</item>
{{VALUES_STYLES_SPLASH}}
</style>
</resources>

<!--
Generate by ReNative (https://renative.org)
BASE: packages/sdk-android/supportFiles/styles_xml.json
-->

{{PLUGIN_STYLES_XML_FILE}}
40 changes: 24 additions & 16 deletions packages/sdk-android/src/manifestParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import {
_getConfigProp,
ConfigFileBuildConfig,
getContext,
AndroidResourcesNode,
} from '@rnv/core';
import { Context } from './types';
import { getBuildFilePath, getAppId, addSystemInjects } from '@rnv/sdk-utils';

const PROHIBITED_DUPLICATE_TAGS = ['intent-filter'];
const SYSTEM_TAGS = ['tag', 'children'];

const _findChildNode = (tag: string, name: string, node: AndroidManifestNode) => {
const _findChildNode = (tag: string, name: string, node: AndroidManifestNode | AndroidResourcesNode) => {
if (!node) {
logWarning('_findChildNode: Node is undefined');
return;
Expand All @@ -36,7 +37,11 @@ const _findChildNode = (tag: string, name: string, node: AndroidManifestNode) =>
for (let i = 0; i < node.children.length; i++) {
const ch = node.children?.[i];
if (ch && ch.tag === tag) {
if (ch['android:name'] === name || PROHIBITED_DUPLICATE_TAGS.includes(tag)) {
if (
('android:name' in ch && ch['android:name'] === name) ||
('name' in ch && ch['name'] === name) ||
PROHIBITED_DUPLICATE_TAGS.includes(tag)
) {
return ch;
}
}
Expand All @@ -46,11 +51,11 @@ const _findChildNode = (tag: string, name: string, node: AndroidManifestNode) =>
return null;
};

const _convertToXML = (manifestObj: AndroidManifestNode) => _parseNode(manifestObj, 0);
export const _convertToXML = (manifestObj: AndroidManifestNode | AndroidResourcesNode) => _parseNode(manifestObj, 0);

type NodeKey = keyof AndroidManifestNode;
type NodeKeyChildren = keyof AndroidManifestNode['children'] | keyof AndroidResourcesNode['children'];

const _parseNode = (n: AndroidManifestNode, level: number) => {
const _parseNode = <T extends AndroidManifestNode | AndroidResourcesNode>(n: T, level: number) => {
let output = '';
let space = '';
for (let i = 0; i < level; i++) {
Expand All @@ -73,7 +78,7 @@ const _parseNode = (n: AndroidManifestNode, level: number) => {
output += `${space}<${n.tag}${endLine}`;
Object.keys(n).forEach((k) => {
if (!SYSTEM_TAGS.includes(k)) {
output += `${isSingleLine ? '' : `${space} `}${k}="${n[k as NodeKey]}"${endLine}`;
output += `${isSingleLine ? '' : `${space} `}${k}="${n[k as keyof T]}"${endLine}`;
}
});
}
Expand All @@ -98,9 +103,9 @@ const _parseNode = (n: AndroidManifestNode, level: number) => {
return output;
};

const _mergeNodeParameters = (
node: AndroidManifestNode | undefined,
nodeParamsExt: AndroidManifestNode | undefined
export const _mergeNodeParameters = <T extends AndroidManifestNode | AndroidResourcesNode>(
node: T | undefined,
nodeParamsExt: T | undefined
) => {
if (!nodeParamsExt) {
logWarning('_mergeNodeParameters: nodeParamsExt value is null');
Expand All @@ -112,25 +117,28 @@ const _mergeNodeParameters = (
}

Object.keys(nodeParamsExt).forEach((k) => {
const key = k as NodeKey;
const val = nodeParamsExt[key];
const key = k as keyof T;
const val = (nodeParamsExt as T)[key];

if (val !== 'undefined' && !SYSTEM_TAGS.includes(k)) {
//TODO: fix this
(node as Record<string, any>)[key] = val;
(node as T)[key] = val;
}
});
};

const _mergeNodeChildren = (node: AndroidManifestNode, nodeChildrenExt: Array<AndroidManifestNode> = []) => {
export const _mergeNodeChildren = <T extends AndroidManifestNode | AndroidResourcesNode>(
node: T,
nodeChildrenExt: Array<T> = []
) => {
// console.log('_mergeNodeChildren', node, 'OVERRIDE', nodeChildrenExt);
if (!node) {
logWarning('_mergeNodeChildren: Node is undefined');
return;
}
if (!node.children) node.children = [];
nodeChildrenExt.forEach((v) => {
const nameExt = v['android:name'];
const nameExt = 'android:name' in v ? v['android:name'] : v.name;
if (v.tag) {
const childNode = _findChildNode(v.tag, nameExt, node);
if (childNode) {
Expand All @@ -139,7 +147,7 @@ const _mergeNodeChildren = (node: AndroidManifestNode, nodeChildrenExt: Array<An
_mergeNodeChildren(childNode, v.children);
} else {
logDebug(`_mergeNodeChildren: NO android:name found. adding to children ${nameExt} ${v.tag}`);
if (node.children) node.children.push(v);
if (node.children) node.children.push(v as NodeKeyChildren);
}
}
});
Expand Down Expand Up @@ -177,7 +185,7 @@ const _mergeFeatures = (
}
};

const getConfigPropArray = <T extends ConfigPropKey>(c: RnvContext, platform: RnvPlatform, key: T) => {
export const getConfigPropArray = <T extends ConfigPropKey>(c: RnvContext, platform: RnvPlatform, key: T) => {
const result: Array<ConfigProp[T]> = [];
const configArr = [
c.files.defaultWorkspace.config,
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk-android/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
parseValuesStringsSync,
injectPluginXmlValuesSync,
parseValuesColorsSync,
parseValuesStylesSync,
parseValuesXml,
} from './xmlValuesParser';
import { ejectGradleProject } from './ejector';
import { AndroidDevice, Context, Payload } from './types';
Expand Down Expand Up @@ -497,7 +497,8 @@ export const configureProject = async () => {
parseMainApplicationSync();
parseSplashActivitySync();
parseValuesStringsSync();
parseValuesStylesSync();
parseValuesXml('styles_xml');
// parseValuesStylesSync();
parseValuesColorsSync();
parseAndroidManifestSync();
parseGradlePropertiesSync();
Expand Down
Loading