@@ -139,6 +139,17 @@ class ComposeFragment : Fragment() {
139139 * Expand the recipient [chip] into a popup with a list of contact addresses to choose from.
140140 */
141141 private fun expandChip (chip : View ) {
142+ // Configure the analogous collapse transform back to the recipient chip. This should
143+ // happen when the card is clicked, any region outside of the card (the card's transparent
144+ // scrim) is clicked, or when the back button is pressed.
145+ binding.run {
146+ recipientCardView.setOnClickListener { collapseChip(chip) }
147+ recipientCardScrim.visibility = View .VISIBLE
148+ recipientCardScrim.setOnClickListener { collapseChip(chip) }
149+ }
150+ closeRecipientCardOnBackPressed.expandedChip = chip
151+ closeRecipientCardOnBackPressed.isEnabled = true
152+
142153 val transform = MaterialContainerTransform ().apply {
143154 startView = chip
144155 endView = binding.recipientCardView
@@ -152,17 +163,6 @@ class ComposeFragment : Fragment() {
152163 addTarget(binding.recipientCardView)
153164 }
154165
155- // Configure the analogous collapse transform back to the recipient chip. This should
156- // happen when the card is clicked, any region outside of the card (the card's transparent
157- // scrim) is clicked, or when the back button is pressed.
158- binding.run {
159- recipientCardView.setOnClickListener { collapseChip(chip) }
160- recipientCardScrim.visibility = View .VISIBLE
161- recipientCardScrim.setOnClickListener { collapseChip(chip) }
162- }
163- closeRecipientCardOnBackPressed.expandedChip = chip
164- closeRecipientCardOnBackPressed.isEnabled = true
165-
166166 TransitionManager .beginDelayedTransition(binding.composeConstraintLayout, transform)
167167 binding.recipientCardView.visibility = View .VISIBLE
168168 // Using INVISIBLE instead of GONE ensures the chip's parent layout won't shift during
@@ -174,6 +174,11 @@ class ComposeFragment : Fragment() {
174174 * Collapse the recipient card back into its [chip] form.
175175 */
176176 private fun collapseChip (chip : View ) {
177+ // Remove the scrim view and on back pressed callbacks
178+ binding.recipientCardScrim.visibility = View .GONE
179+ closeRecipientCardOnBackPressed.expandedChip = null
180+ closeRecipientCardOnBackPressed.isEnabled = false
181+
177182 val transform = MaterialContainerTransform ().apply {
178183 startView = binding.recipientCardView
179184 endView = chip
@@ -184,11 +189,6 @@ class ComposeFragment : Fragment() {
184189 addTarget(chip)
185190 }
186191
187- // Remove the scrim view and on back pressed callbacks
188- binding.recipientCardScrim.visibility = View .GONE
189- closeRecipientCardOnBackPressed.expandedChip = null
190- closeRecipientCardOnBackPressed.isEnabled = false
191-
192192 TransitionManager .beginDelayedTransition(binding.composeConstraintLayout, transform)
193193 chip.visibility = View .VISIBLE
194194 binding.recipientCardView.visibility = View .INVISIBLE
0 commit comments