In border towns like this, in a House district represented by a Democrat, Mr. Trump’s reign has become a galvanizing force for both sides. As Mr. Ryan prepared on Wednesday to meet with officials at a Department of Homeland Security building in McAllen, Tex., protesters waited to greet him across a highway. “Keep the kids, deport the racists,” one sign read. Quickly, a chant broke out: “Puentes, no muros.” Bridges, not walls.

Others expressed disappointment in Mr. Ryan, a politician they once viewed as moderate on immigration.

“At one time, I did think he was going to work for us,” said Gloria Rodriguez, 60, of Harlingen, Tex., recalling Mr. Ryan’s criticisms of Mr. Trump last year.

But behind her, across the highway, a truck driver had rolled down his window. “Donald Truuuuuuump!” he shouted, turning his head back as he rolled. “Yeahhhhhh!”

Mr. Ryan’s office said little about his visit beforehand and declined for several days to confirm a report by The Monitor of McAllen last week about his visit here. By late afternoon on Wednesday, aides confirmed the basics of Mr. Ryan’s day: a helicopter tour, a horse patrol demonstration, the boat ride, a stop at a United States Customs and Border Protection operating hub, and a meeting with local leaders.

“When you see with your own eyes the many challenges facing our law enforcement professionals along the border, it gives you even greater respect for the work that they do day in and day out,” Mr. Ryan said in a statement after the visit. “But more tools and more support are needed for them to do their jobs effectively. Congress is committed to securing the border and enforcing our laws, and together with the Trump administration, we will get this done.”