fix(StatusItemsSelector): Allow icons to be provided by the model

Fixing https://github.com/status-im/status-desktop/issues/9766
The main change is that the model will now provide the image type, on top of the image source. The image type can be either icon or image. Icons will be coloured with the same colour as the text.
This commit is contained in:
Alex Jbanca 2023-03-27 14:51:58 +03:00 committed by Alex Jbanca
parent 17834ecbc1
commit 75571c9f22
6 changed files with 33 additions and 12 deletions

View File

@ -44,6 +44,7 @@ ColumnLayout {
model.append({ model.append({
text: input.text, text: input.text,
imageSource: Style.png("tokens/SNT"), imageSource: Style.png("tokens/SNT"),
isIcon: false,
operator: model.count > 0 ? OperatorsUtils.Operators.Or operator: model.count > 0 ? OperatorsUtils.Operators.Or
: OperatorsUtils.Operators.None : OperatorsUtils.Operators.None
}) })

View File

@ -55,6 +55,7 @@ StatusFlowSelector {
ListElement { ListElement {
text: "Socks" text: "Socks"
imageSource: "qrc:imports/assets/png/tokens/SOCKS.png" imageSource: "qrc:imports/assets/png/tokens/SOCKS.png"
isIcon: false
color: "" color: ""
emoji: "" emoji: ""
operator: Utils.Operator.None operator: Utils.Operator.None
@ -62,6 +63,7 @@ StatusFlowSelector {
ListElement { ListElement {
text: "ZRX" text: "ZRX"
imageSource: "qrc:imports/assets/png/tokens/ZRX.png" imageSource: "qrc:imports/assets/png/tokens/ZRX.png"
isIcon: false
color: "" color: ""
emoji: "" emoji: ""
operator: Utils.Operator.Or operator: Utils.Operator.Or
@ -69,6 +71,7 @@ StatusFlowSelector {
ListElement { ListElement {
text: "Custom Token" text: "Custom Token"
imageSource: "" imageSource: ""
isIcon: true
color: "red" color: "red"
emoji: "⚽" emoji: "⚽"
operator: Utils.Operator.Or operator: Utils.Operator.Or
@ -77,18 +80,13 @@ StatusFlowSelector {
\endqml \endqml
*/ */
property alias model: repeater.model property alias model: repeater.model
/*!
\qmlproperty bool StatusItemSelector::useIcons
This property determines if the imageSource role from the model will be handled as
an image or an icon.
*/
property bool useIcons: false
property StatusAssetSettings asset: StatusAssetSettings { property StatusAssetSettings asset: StatusAssetSettings {
height: 20 height: 20
width: 20 width: 20
bgHeight: height
bgWidth: width
bgColor: "transparent" bgColor: "transparent"
isImage: !root.useIcons
isLetterIdenticon: root.useLetterIdenticons isLetterIdenticon: root.useLetterIdenticons
} }
property int tagLeftPadding: 6 property int tagLeftPadding: 6
@ -146,11 +144,13 @@ StatusFlowSelector {
asset.height: root.asset.height asset.height: root.asset.height
asset.width: root.asset.width asset.width: root.asset.width
asset.bgHeight: root.asset.bgHeight
asset.bgWidth: root.asset.bgWidth
asset.name: root.useLetterIdenticons ? model.text : (model.imageSource ?? "") asset.name: root.useLetterIdenticons ? model.text : (model.imageSource ?? "")
asset.isImage: root.asset.isImage asset.isImage: !model.isIcon
asset.bgColor: root.asset.bgColor asset.bgColor: root.asset.bgColor
asset.emoji: model.emoji ? model.emoji : "" asset.emoji: model.emoji ? model.emoji : ""
asset.color: model.color ? model.color : "" asset.color: model.color ? model.color : titleText.color
asset.isLetterIdenticon: root.useLetterIdenticons asset.isLetterIdenticon: root.useLetterIdenticons
closeButtonVisible: false closeButtonVisible: false
titleText.color: Theme.palette.primaryColor1 titleText.color: Theme.palette.primaryColor1

View File

@ -102,10 +102,13 @@ Control{
leftPadding: 2 leftPadding: 2
title: model.text title: model.text
asset.name: model.imageSource asset.name: model.imageSource
asset.isImage: true asset.isImage: !model.isIcon
asset.bgColor: "transparent" asset.bgColor: "transparent"
asset.color: asset.isImage ? "transparent" : titleText.color
asset.height: 28 asset.height: 28
asset.width: asset.height asset.width: asset.height
asset.bgHeight: asset.height
asset.bgWidth: asset.height
closeButtonVisible: false closeButtonVisible: false
titleText.color: Theme.palette.primaryColor1 titleText.color: Theme.palette.primaryColor1
titleText.font.pixelSize: d.tagTextPixelSize titleText.font.pixelSize: d.tagTextPixelSize

View File

@ -74,10 +74,13 @@ Control {
leftPadding: 2 leftPadding: 2
title: model.text title: model.text
asset.name: model.imageSource asset.name: model.imageSource
asset.isImage: true asset.isImage: !model.isIcon
asset.bgColor: "transparent" asset.bgColor: "transparent"
asset.height: 28 asset.height: 28
asset.width: asset.height asset.width: asset.height
asset.bgWidth: asset.height
asset.bgHeight: asset.height
asset.color: asset.isImage ? "transparent" : titleText.color
closeButtonVisible: false closeButtonVisible: false
titleText.color: model.available ? Theme.palette.primaryColor1 : Theme.palette.dangerColor1 titleText.color: model.available ? Theme.palette.primaryColor1 : Theme.palette.dangerColor1
bgColor: model.available ? Theme.palette.primaryColor2 :Theme.palette.dangerColor2 bgColor: model.available ? Theme.palette.primaryColor2 :Theme.palette.dangerColor2

View File

@ -475,6 +475,7 @@ StatusScrollView {
Component.onCompleted: { Component.onCompleted: {
append({ append({
imageSource: inDropdown.communityImage, imageSource: inDropdown.communityImage,
isIcon: false,
text: inDropdown.communityName, text: inDropdown.communityName,
operator: OperatorsUtils.Operators.None, operator: OperatorsUtils.Operators.None,
color: inDropdown.communityColor color: inDropdown.communityColor

View File

@ -56,7 +56,7 @@ SortFilterProxyModel {
function getIcon(type, key) { function getIcon(type, key) {
if (type === HoldingTypes.Type.Ens) if (type === HoldingTypes.Type.Ens)
return Style.svg("profile/ensUsernames") return "username"
const model = type === HoldingTypes.Type.Asset const model = type === HoldingTypes.Type.Asset
? assetsModel : collectiblesModel ? assetsModel : collectiblesModel
@ -70,6 +70,19 @@ SortFilterProxyModel {
return getIcon(model.type, model.key) return getIcon(model.type, model.key)
} }
}, },
ExpressionRole {
name: "isIcon"
function isIconType(type) {
return type === HoldingTypes.Type.Ens
}
expression: {
_assetsChanges.revision
_collectiblesChanges.revision
return isIconType(model.type)
}
},
ExpressionRole { ExpressionRole {
name: "operator" name: "operator"