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

Compose object imports #874

Merged
merged 4 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
204 changes: 0 additions & 204 deletions examples/advanced/multi-brand-multi-platform/yarn.lock

This file was deleted.

3 changes: 2 additions & 1 deletion lib/common/formatHelpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
sortByReference: require('./sortByReference'),
sortByName: require('./sortByName'),
minifyDictionary: require('./minifyDictionary'),
setSwiftFileProperties: require('./setSwiftFileProperties')
setSwiftFileProperties: require('./setSwiftFileProperties'),
setComposeObjectProperties: require('./setComposeObjectProperties')
}
30 changes: 30 additions & 0 deletions lib/common/formatHelpers/setComposeObjectProperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

/**
* Outputs an object for compose format configurations. Sets import.
* @memberof module:formatHelpers
* @param {Object} options - The options object declared at configuration
* @returns {Object}
*/
function setComposeObjectProperties(options) {
if (typeof options.import === 'undefined') {
options.import = ['androidx.compose.ui.graphics.Color', 'androidx.compose.ui.unit.*'];
} else if (typeof options.import === 'string') {
options.import = [options.import];
}

return options
}

module.exports = setComposeObjectProperties;
5 changes: 4 additions & 1 deletion lib/common/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fs = require('fs');
const path = require('path');
const _template = require('lodash/template');
const GroupMessages = require('../utils/groupMessages');
const { fileHeader, formattedVariables, getTypeScriptType, iconsWithPrefix, minifyDictionary, sortByReference, createPropertyFormatter, sortByName, setSwiftFileProperties } = require('./formatHelpers');
const { fileHeader, formattedVariables, getTypeScriptType, iconsWithPrefix, minifyDictionary, sortByReference, createPropertyFormatter, sortByName, setSwiftFileProperties, setComposeObjectProperties } = require('./formatHelpers');

const SASS_MAP_FORMAT_DEPRECATION_WARNINGS = GroupMessages.GROUP.SassMapFormatDeprecationWarnings;

Expand Down Expand Up @@ -706,6 +706,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
* @param {String} className The name of the generated Kotlin object
* @param {String} packageName The package for the generated Kotlin object
* @param {Object} options
* * @param {String[]} [options.import=androidx.compose.ui.unit.*] - Modules to import. Can be a string or array of string
* @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date
* @param {Boolean} [options.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output.
* @example
Expand Down Expand Up @@ -740,6 +741,8 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
allProperties = [...dictionary.allProperties].sort(sortByName);
}

options = setComposeObjectProperties(options);
giovannimartusciello marked this conversation as resolved.
Show resolved Hide resolved

return template({allProperties, file, options, formatProperty, fileHeader});
},

Expand Down
7 changes: 4 additions & 3 deletions lib/common/templates/compose/object.kt.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

package <%= file.packageName %>;

<% // Ideally we would selectively import the correct classes & functions based on whether the applied transforms actually need them. %>
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.*
<%= options.import.map(function(item) {
return 'import ' + item
}).join('\n')
%>

object <%= file.className %> {
giovannimartusciello marked this conversation as resolved.
Show resolved Hide resolved
<%= allProperties.map(function(prop) {
Expand Down